📜  如何设置 React Context,useContext Hook - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:37.340000             🧑  作者: Mango

代码示例1
export const AuthContext = createContext(INITIAL_STATE);

export const AuthContextProvider = ({ children }) => {
  const [state, dispatch] = useReducer(authReducer, INITIAL_STATE);

  useEffect(() => {
    localStorage.setItem("user", JSON.stringify(state.user));
  }, [state]);

  return (
    
      {children}
    
  );
};

export default AuthContext;