Skip to content

Instantly share code, notes, and snippets.

@vzaidman
Last active May 23, 2020 07:41
Show Gist options
  • Save vzaidman/9ac923475d9e926b4b5c3f22374c0eca to your computer and use it in GitHub Desktop.
Save vzaidman/9ac923475d9e926b4b5c3f22374c0eca to your computer and use it in GitHub Desktop.
Advanced React- useCallback() Invalidates Too Often in Practice #14099
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