import {createContext, useContext} from 'react';
export type AuthContext = {
isAuth: boolean
setIsAuth: (b: boolean) => void
}
export const AuthContext = createContext<AuthContext>({
isAuth: false,
setIsAuth: () => undefined
})
export const useAuthContext = () => useContext(AuthContext)
// usage
const {isAuth, setIsAuth} = useAuthContext()
function App() {
const [isAuth, setIsAuth] = useState(false)
return (
<div className="App">
<AuthContext.Provider value={{isAuth, setIsAuth}}>
<Header/>
</AuthContext.Provider>
</div>
);
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter