Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
Last active March 23, 2021 07:13
Show Gist options
  • Save night-fury-rider/90b091c750464838ad58fe485ca5b503 to your computer and use it in GitHub Desktop.
Save night-fury-rider/90b091c750464838ad58fe485ca5b503 to your computer and use it in GitHub Desktop.
React - Hook useMemo
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