Used to cache values or functions based on dependencies, preventing unnecessary recalculations or recreations on re-render.

useMemo()

Caches the return value of a computation.

const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);

Use when:

useCallback()

Caches the function reference, so it remains stable across renders.

const handleClick = useCallback(() => {
  console.log('clicked');
}, []);

Use when: