Skip to content

Instantly share code, notes, and snippets.

@mjgil
Created March 19, 2016 22:50
Show Gist options
  • Save mjgil/d9f576cf4cb60b42cbb6 to your computer and use it in GitHub Desktop.
Save mjgil/d9f576cf4cb60b42cbb6 to your computer and use it in GitHub Desktop.
// How to do this.bind
// ES7 syntax
render() {
<div onClick={::this.onClick}> </div>
}
onClick() {
}
///////////////////
///////////////////
// arrow functions automatically binds this
render() {
<div onClick={() => this.onClick}> </div>
}
render() {
<div onClick={this.onClick.bind(this)}> </div>
}
// make this.onClick an arrow function
render() {
<div onClick={this.onClick}> </div>
}
onClick = () => {
}
// nest the arrow function in onClick
render() {
<div onClick={this.onClick}> </div>
}
onClick() {
return () => {
this.someFunction()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment