Skip to content

Instantly share code, notes, and snippets.

@rushil1999
Created August 29, 2022 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rushil1999/4e5b95646231d4f9096e6a5c112221d1 to your computer and use it in GitHub Desktop.
Save rushil1999/4e5b95646231d4f9096e6a5c112221d1 to your computer and use it in GitHub Desktop.
import React,{useState, createContext} from 'react';
//Creating a context using 'createContext'
export const AuthContext = createContext(null);
const AuthContextProvider = ({children}) =>{
//Boolean value that would simply indicate whether User is signed in or nor
const [authState, setAuthState] = useState(false);
//Object to store other user details like name, email, etc
const [userDetails, setUserDetails] = useState({});
return(
// Passing all the state and state change functions to all the components down in the tree, for them to get access of THIS component's state
<AuthContext.Provider value={[authState, setAuthState, userDetails, setUserDetails]}>
{children}
</AuthContext.Provider>
)
}
export default AuthContextProvider;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment