const UserContext = React.createContext(); // could have a default value
2
3function UserCtxProvider({ children }) {
4 const [authUser, setAuthUser] = React.useState(null);
5
6 const value = React.useMemo(() => ({
7 authUser, setAuthUser
8 }), [authUser]);
9
10 return (
11 <UserContext.Provider value={value}>
12 {children}
13 <UserContext.Provider>
14 );
15}
16
17function App() {
18 return (
19 <UserCtxProvider>
20 <Login />
21 <Home />
22 {/* Rest of the app */}
23 </UserCtxProvider>
24 );
25}