Skip to content

Instantly share code, notes, and snippets.

@nirnejak
Created December 9, 2021 09:15
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 nirnejak/c317b1111f54c194d21741c399b91d98 to your computer and use it in GitHub Desktop.
Save nirnejak/c317b1111f54c194d21741c399b91d98 to your computer and use it in GitHub Desktop.
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