Hook that lets you memoize
/cache
results of calculation between renders
Use it when it would make a difference by preventing wasted re-renders.
Use useMemo
to keep expensive, resource intensive functions from needlessly running.
const cachedValue = useMemo(calculatedValue, dependencies);
useCallback
useCallback
is similar to useMemo
, difference is that useCallback
returns a memoized function whereas useMemo
returns a memoized value