Last active
March 23, 2021 07:13
-
-
Save night-fury-rider/90b091c750464838ad58fe485ca5b503 to your computer and use it in GitHub Desktop.
React - Hook useMemo
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
import React, { useMemo } from 'react'; | |
function App() { | |
const arr = [1, 2, 33, 4]; | |
// Memorize output as long as dependency array elements are not changed. | |
const memiozedValue = useMemo(() => getLargestValue(), [arr]); | |
function getLargestValue() { | |
return Math.max(...arr); | |
} | |
return ( | |
<> | |
<div>Array: {arr}</div> | |
<div>Memiozed Value: {memiozedValue}</div> | |
</> | |
) | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment