Created
August 29, 2022 03:09
-
-
Save rushil1999/4e5b95646231d4f9096e6a5c112221d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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