Skip to content

Instantly share code, notes, and snippets.

@becca-bailey
Created November 15, 2018 03:17
Show Gist options
  • Save becca-bailey/1ed8a8c8e734f0f8cbe735c88dfc56ff to your computer and use it in GitHub Desktop.
Save becca-bailey/1ed8a8c8e734f0f8cbe735c88dfc56ff to your computer and use it in GitHub Desktop.
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