Created
February 28, 2019 08:14
-
-
Save 3nvi/5a79e6c1553e67813d50d1a43bf74866 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
// don't do this! | |
function Component(props) { | |
const someProp = heavyCalculation(props.item); | |
return <AnotherComponent someProp={someProp} /> | |
} | |
// do this instead. Now `someProp` will be recalculated | |
// only when `props.item` changes | |
function Component(props) { | |
const someProp = useMemo(() => heavyCalculation(props.item), [props.item]); | |
return <AnotherComponent someProp={someProp} /> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment