Created
January 16, 2018 22:25
-
-
Save johnnyji/f006bb21185bb2a6ba62b39ea38cd692 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
class Main extends React.Component { | |
// ... | |
render() { | |
// Because we've named the prop `this._handleClick`, we're now passing a FUNCTION REFERENCE and | |
// no longer creating a new function on every render cycle. The function reference will not change throughout | |
// the lifecycle of `Main`, therefore it will never cause `Button` to re-render. | |
return ( | |
<div> | |
<p>This button has been clicked {count} times</p> | |
<Button onClick={this._handleClicked} /> | |
</div> | |
); | |
} | |
_handleClicked = () => { | |
// ... | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment