Last active
August 28, 2018 19:10
-
-
Save becca-bailey/2d8a0b9502f629f53bf91a3a0495af79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ParentClass extends React.Component { | |
| state = { | |
| alert: undefined | |
| }; | |
| render() { | |
| return ( | |
| <SimpleComponentWithAlert renderAlert={this.renderAlert} showAlert={this.showAlert} /> | |
| ) | |
| } | |
| private renderAlert = () => { | |
| if (this.state.alert) { | |
| return <FancyAlertMessage alert={this.state.alert} /> | |
| } | |
| } | |
| private showAlert = alert => { | |
| this.setState({ | |
| alert | |
| }); | |
| }; | |
| } | |
| class SimpleComponentWithAlert extends React.Component { | |
| render() { | |
| const myAlert = { | |
| message: "This is my alert", | |
| type: "error" | |
| }; | |
| return ( | |
| <div> | |
| {this.props.renderAlert()} | |
| <button onClick={this.props.showAlert(myAlert)}>Show Alert</button> | |
| </div> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment