Skip to content

Instantly share code, notes, and snippets.

@ristaa
Created August 14, 2018 13:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ristaa/bc6aa4952d2ed16e5e5ec89d0a476e3e to your computer and use it in GitHub Desktop.
Bind this using ES6 arrow function in render - 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()}
/>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment