Created
March 5, 2019 01:12
-
-
Save treyhuffine/3fda76e61e69b664d5209bb3e3057b45 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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