Last active
May 23, 2020 07:41
-
-
Save vzaidman/9ac923475d9e926b4b5c3f22374c0eca 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> | |
); | |
}); | |
const Parent = () => { | |
console.log('parent!'); | |
const handleClick = () => console.log('hi!'); | |
return ( | |
<PureHeavyComponent onClick={handleClick} /> | |
); | |
}; | |
// results: | |
// first render: | |
<Parent/> | |
// parent! | |
// pure heavy component! | |
// next renders: | |
<Parent/> | |
// parent! | |
// pure heavy component! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment