Skip to content

Instantly share code, notes, and snippets.

@3nvi
Created February 28, 2019 08:14
Show Gist options
  • Save 3nvi/5a79e6c1553e67813d50d1a43bf74866 to your computer and use it in GitHub Desktop.
Save 3nvi/5a79e6c1553e67813d50d1a43bf74866 to your computer and use it in GitHub Desktop.
// 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