useMemo

The React hook that caches the result of a calculation between renders and recalculates only when its dependencies change.

In more detail

Use it for expensive calculations or to keep an object prop stable for a memoized child. React may throw the cache away, so code must still work without it.

Example

const config = useMemo(() => ({ query, limit }), [query, limit]);

Related terms

Taught in

References