Created
March 19, 2016 22:50
-
-
Save mjgil/d9f576cf4cb60b42cbb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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