Created
December 9, 2021 09:15
-
-
Save nirnejak/c317b1111f54c194d21741c399b91d98 to your computer and use it in GitHub Desktop.
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 React from "react" | |
import PropTypes from "prop-types" | |
const initialState = { | |
isAuthenticated: false, | |
} | |
export const AuthContext = React.createContext(initialState) | |
export const AuthProvider = ({ children }) => { | |
const [isAuthenticated, setIsAuthenticated] = React.useState(false) | |
const loginUser = () => { | |
setIsAuthenticated(true) | |
} | |
const logoutUser = () => { | |
setIsAuthenticated(false) | |
} | |
return ( | |
<AuthContext.Provider | |
value={{ | |
isAuthenticated, | |
loginUser, | |
logoutUser, | |
}} | |
> | |
{children} | |
</AuthContext.Provider> | |
) | |
} | |
AuthProvider.propTypes = { | |
children: PropTypes.node.isRequired, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment