I am using react hooks and context api . I get a user info. when i log in, which was null by default in the context. But when i refresh the page the value does not persist in the context api . How can i save the user info. ?
import AuthReducer from "./AuthReducer";
const INITIAL_STATE = {
user: null,
isFetching: false,
error: false,
};
export const AuthContext = createContext(INITIAL_STATE);
export const AuthContextProvider = ({ children }) => {
const [state, dispatch] = useReducer(AuthReducer, INITIAL_STATE);
return (
<AuthContext.Provider
value={{
user: state.user,
isFetching: state.isFetching,
error: state.error,
dispatch,
}}
>
{children}
</AuthContext.Provider>
);
};