Skip to content

Instantly share code, notes, and snippets.

@vikpande
Created August 7, 2017 18:12
Show Gist options
  • Save vikpande/c0fed384b2d7570aa3712591ea1efbb2 to your computer and use it in GitHub Desktop.
Save vikpande/c0fed384b2d7570aa3712591ea1efbb2 to your computer and use it in GitHub Desktop.
React snippets
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