Created
August 7, 2017 18:12
-
-
Save vikpande/c0fed384b2d7570aa3712591ea1efbb2 to your computer and use it in GitHub Desktop.
React snippets
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 SayHello extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = {message: 'Hello!'}; | |
| // This line is important! | |
| this.handleClick = this.handleClick.bind(this); | |
| } | |
| handleClick() { | |
| alert(this.state.message); | |
| } | |
| render() { | |
| // Because `this.handleClick` is bound, we can use it as an event handler. | |
| return ( | |
| <button onClick={this.handleClick}> | |
| Say hello | |
| </button> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment