Hooks API Reference – React
A JavaScript library for building user interfaces
React
use-memo
const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);
It returns a memoized value.
() => computeExpensiveValue(a, b)
)[a, b]
)useMemo
will only recompute the memoized value when one of the dependencies has changed. This optimization helps to avoid expensive calculations on every render.
use-memo
use-memo
due to the overhead of use-memo
.use-memo
maintains variable objects, so it is helpful to avoid re-rendering when not needed.Make sure to profile the component with and without use-memo
. Only after they conclude whether memoization is worth it.
When memoization is misused, it could harm the performance.