Created
March 27, 2019 23:42
-
-
Save jondeandres/7cb5eb797aaffe90964c8b1ad6eb713f to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Can you explain the differences between all those ways | |
* of passing function to a component? | |
* | |
* What happens when you click each of the buttons? | |
*/ | |
class App extends React.Component { | |
constructor() { | |
super(); | |
this.name = 'MyComponent'; | |
this.handleClick2 = this.handleClick1.bind(this); | |
} | |
handleClick1() { | |
alert(this.name); | |
} | |
handleClick3 = () => alert(this.name); | |
render() { | |
return ( | |
<div> | |
<button onClick={this.handleClick1()}>click 1</button> | |
<button onClick={this.handleClick1}>click 2</button> | |
<button onClick={this.handleClick2}>click 3</button> | |
<button onClick={this.handleClick3}>click 4</button> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment