Created
November 15, 2018 03:15
-
-
Save becca-bailey/c8539d869b3ef4553381356734ea670e 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
const AlertContext = React.createContext<IAlertContext>({ | |
alert: undefined, | |
showAlert: (alert) => {}, | |
}); | |
// Here we are creating a context with default values | |
class AlertProvider extends React.Component { | |
state = { | |
alert: undefined | |
}; | |
render() { | |
const { children } = this.props; | |
return ( | |
<AlertContext.Provider | |
value={{ | |
...this.state, | |
showAlert: this.showAlert, | |
}} | |
> | |
{children} | |
</AlertContext.Provider> | |
); | |
} | |
private showAlert = alert => { | |
this.setState({ | |
alert | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment