Skip to content

Instantly share code, notes, and snippets.

@rainstormza
Created November 30, 2018 10:50
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 rainstormza/fa890a0081ff65e459d70c4585530f12 to your computer and use it in GitHub Desktop.
Save rainstormza/fa890a0081ff65e459d70c4585530f12 to your computer and use it in GitHub Desktop.
React Context API contextType example.
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