Created
January 29, 2022 16:52
-
-
Save alperbayram/9f3fbc01264b6a930ab338d0ff63bff5 to your computer and use it in GitHub Desktop.
AuthContext
This file contains 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 { useState, createContext, useContext } from "react"; | |
const AuthContext = createContext(); | |
function AuthProvider({ children }) { | |
const [loggedIn, setLoggedIn] = useState(false); | |
const login = () => { | |
setLoggedIn(true); | |
}; | |
const logout = () => { | |
setLoggedIn(false); | |
}; | |
const values = { | |
loggedIn, | |
login, | |
logout, | |
}; | |
return <AuthContext.Provider value={values}>{children}</AuthContext.Provider>; | |
} | |
const useAuth = () => useContext(AuthContext); | |
export { AuthProvider, useAuth }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment