useMemo will only recompute the memoized value when one of the deps has changed.
useMemo
deps
Usage note: if calling useMemo with a referentially stable function, also give it as the input in the second argument.
function expensive () { ... }function Component () { const expensiveResult = useMemo(expensive, [expensive]) return ...} Copy
function expensive () { ... }function Component () { const expensiveResult = useMemo(expensive, [expensive]) return ...}
16.8.0
https://reactjs.org/docs/hooks-reference.html#usememo
useMemo
will only recompute the memoized value when one of thedeps
has changed.Usage note: if calling
useMemo
with a referentially stable function, also give it as the input in the second argument.