Skip to content

Instantly share code, notes, and snippets.

@sabesansathananthan
Created November 5, 2019 18:25
Show Gist options
  • Save sabesansathananthan/24acb9df2c4e9131ff7e127abd797e48 to your computer and use it in GitHub Desktop.
Save sabesansathananthan/24acb9df2c4e9131ff7e127abd797e48 to your computer and use it in GitHub Desktop.
example 3 for react best practice to handle this
class Hello extends Components {
constructor(props) {
super(props);
this.state = { message: "Hello" };
this.logMessage = this.logMessage.bind(this);
}
logMessage() {
const { message } = this.state;
console.log(message);
}
render() {
return (
<input type="button" value="Log" onClick={this.logMessage} />
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment