Skip to content

Instantly share code, notes, and snippets.

@johnnyji
Created January 16, 2018 22:25
Show Gist options
  • Save johnnyji/f006bb21185bb2a6ba62b39ea38cd692 to your computer and use it in GitHub Desktop.
Save johnnyji/f006bb21185bb2a6ba62b39ea38cd692 to your computer and use it in GitHub Desktop.
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