memo, useMemo and useCallback
Three tools, one idea. Skip work that would produce the same answer.
React.memo skips re-rendering a component when its props have not changed.
useMemo caches a computed value between renders.
useCallback caches a function between renders.
Why they are usually used together. memo compares props shallowly. A function or object created during the render is a new value every time, so a memoised child with an inline arrow prop re-renders exactly as often as before, and you have added cost for nothing.
That is the trap: memo appears to do nothing, so people add more of it.
A cost, not free. Each of these adds a comparison, a cached value, and code to read. On a component that renders in under a millisecond, that is a net loss.
The honest rule: write it plainly, measure, and optimize the specific thing the profiler points at.
Mark this lesson complete
Signed in, your progress follows you to every device.