Created
April 8, 2020 14:48
-
-
Save dandelionadia/900fd7f476d7313d3ca485476e835fcd 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, { useEffect, useRef, useContext } from "react"; | |
import { AuthContext } from "../../context/auth-context"; | |
export const Cockpit = (props) => { | |
const authContext = useContext(AuthContext); | |
console.log(authContext.authenticated); | |
return ( | |
<> | |
<button onClick={authContext.login}>Log in</button> | |
</> | |
); | |
}; | |
____________________ | |
import React from "react"; | |
//createContext({default value}) | |
//the default value will apply when you don't set any other value. | |
export const AuthContext = React.createContext({ | |
authenticated: false, | |
login: () => {}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment