Skip to content

Instantly share code, notes, and snippets.

@anacampesan
Created September 12, 2017 16:41
Show Gist options
  • Save anacampesan/6c60992bb7fb6b74c3d8ce9b1053a973 to your computer and use it in GitHub Desktop.
Save anacampesan/6c60992bb7fb6b74c3d8ce9b1053a973 to your computer and use it in GitHub Desktop.
Bind functions to events in React
import React from 'react';
export default class Print extends React.Component {
constructor() {
super()
this.printStuff = this.printStuff.bind(this);
}
printStuff() {
console.log('It works! :)');
}
render() {
return(
<button onClick={this.printStuff}>click</button>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment