Hooks API Reference – React
const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);
It returns a memoized value.
() => computeExpensiveValue(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-memodue to the overhead of
use-memomaintains 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.