Skip to content

Instantly share code, notes, and snippets.

@azeezat
Created August 7, 2021 01:31
Show Gist options
  • Save azeezat/26a7978836d31d28224907c0cc7db7e0 to your computer and use it in GitHub Desktop.
Save azeezat/26a7978836d31d28224907c0cc7db7e0 to your computer and use it in GitHub Desktop.
import { createContext, useContext } from "react";
export const initialAuthState = {
isLoggedIn: false,
};
export const AuthContext = createContext({
user: initialAuthState,
updateUserContext: () => {},
clearUserContext: () => {},
});
export const useAuthContext = () => {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error("useAuthContext must be used within an AuthProvider");
}
return context;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment