Skip to content

Instantly share code, notes, and snippets.

@treyhuffine
Created March 5, 2019 01:12
Show Gist options
  • Save treyhuffine/3fda76e61e69b664d5209bb3e3057b45 to your computer and use it in GitHub Desktop.
Save treyhuffine/3fda76e61e69b664d5209bb3e3057b45 to your computer and use it in GitHub Desktop.
const computeExpensiveValue = (end: number) => {
let result = 0;
for (let i = 0; i < end * 1000000; i++) {
for (let j = 0; i < end * 1000; j++) {
result = result + i - j;
}
}
return result;
};
const MyComponent = ({ end = 0 }) => {
const memoizedNumber = React.useMemo<number>(computeExpensiveValue(end))
return (
<DisplayResult result={memoizedNumber} />
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment