Created
November 15, 2018 03:17
-
-
Save becca-bailey/1ed8a8c8e734f0f8cbe735c88dfc56ff 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
class Layout extends React.Component { | |
render() { | |
return ( | |
<AlertContext.Consumerr> | |
{({ alert }) => ( | |
<React.Fragment> | |
{alert && <FancyAlertMessage alert={alert} /> | |
{this.props.children} | |
</React.Fragment> | |
)} | |
</AlertContext.Consumer> | |
); | |
} | |
} | |
class ComponentWithAlert extends React.Component { | |
render() { | |
const myAlert = { message: "This is my alert", type: "error" }; | |
return ( | |
<AlertContext.Consumer> | |
{({ showAlert }) => ( | |
<button onClick={() => showAlert(myAlert)}>Show Alert</button> | |
)} | |
</AlertContext.Consumer> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment