Reactjs 如何在屏幕中处理多个上下文状态?

Reactjs 如何在屏幕中处理多个上下文状态?,reactjs,react-native,react-hooks,Reactjs,React Native,React Hooks,如何在屏幕中处理多个上下文状态 const { state } = useContext(profileContext); const { state,AttendanceInGetByDate } = useContext(AttendanceContax); 可以在分解结构时重命名属性: const { state: profileDAta } = useContext(profileContext); const { state: attendanceData, Attendance

如何在屏幕中处理多个上下文状态

 const { state } = useContext(profileContext);
 const { state,AttendanceInGetByDate } = useContext(AttendanceContax);

可以在分解结构时重命名属性:

const { state: profileDAta } = useContext(profileContext);
const { state: attendanceData, AttendanceInGetByDate } = useContext(AttendanceContax);
有很多关于Javascript中的解构的文章,最近有点炒作()

此外,如果对您造成任何不便,您不必使用带挂钩的解构:

const profile = useContext(profileContext);
const attendance = useContext(AttendanceContax);
...
// here you can refer to profile.state and attendance.state independently

状态为
somethingElse
?不理解
{state as someOthername}=useContext(profileContext)
someOthername.something
这是语法错误