Skip to content

Instantly share code, notes, and snippets.

@ristaa
Created August 14, 2018 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ristaa/4a9102bc1b3011c74f3a3140bb513dc0 to your computer and use it in GitHub Desktop.
Save ristaa/4a9102bc1b3011c74f3a3140bb513dc0 to your computer and use it in GitHub Desktop.
Bind this in render function - react
class App extends React.Component {
constructor(props) {
super(props);
this.state = { message: "Hello World!" };
}
logMessage() {
console.log(this.state.message);
}
render() {
return (
<div className="App">
<input
type="button"
value="Show message"
onClick={this.logMessage.bind(this)}
/>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment