Created
November 30, 2018 10:50
-
-
Save rainstormza/fa890a0081ff65e459d70c4585530f12 to your computer and use it in GitHub Desktop.
React Context API contextType example.
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
class Header extends Component { | |
// Define contextType as static class field. | |
static contextType = UserContext; | |
render() { | |
const user = this.context; | |
return user.isSignedIn ? ( | |
<div>Hello {user.name}</div> | |
) : ( | |
<div>Not signed in</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment