Last active
May 25, 2020 15:59
-
-
Save vzaidman/02011e9d73c61a2c731d853ceea7c486 to your computer and use it in GitHub Desktop.
Advanced React- useCallback() Invalidates Too Often in Practice #14099
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
const PureHeavyComponent = React.memo(({onClick}) => { | |
console.log('pure heavy component!'); | |
return ( | |
<div onClick={onClick}> | |
//Many Other React elements are created here | |
</div> | |
); | |
}); | |
class Parent extends React.Component { | |
state = {count: 0} | |
// always the same function instance | |
handleClick = () => { | |
const {count} = this.state; | |
console.log(`hi #${count}!`); | |
} | |
render() { | |
return ( | |
<> | |
<PureHeavyComponent onClick={this.handleClick} /> | |
<button onClick={() => this.setState({count: this.state.count + 1})}>increase counter</button> | |
</> | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment