Performance · mid
memo, useMemo and useCallback
memo skips re-rendering a component when its props are shallow-equal; useMemo caches a calculated value and useCallback caches a function identity between renders; they only help when the cached identity is actually used for a comparison or the work is expensive.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
memo(Component): on a parent re-render, React compares old and new props one by one withObject.is; if all equal, it reuses the last result.useMemo(() => compute(a, b), [a, b]): recompute only when deps change. Use for expensive calculations or to keep an object/array identity stable for a memoized child or an effect dep.useCallback(fn, deps)isuseMemo(() => fn, deps): same function object between renders. It does not make the function faster.memofails if any prop is new each render: inline objects (style={{...}}), inline arrows (onSelect={() => ...}), and JSXchildren.- Components that read a context still re-render when it changes, even inside
memo. - Costs: memory, comparison time and more complex code. Useless if the props change anyway.
- React may drop a
useMemocache in some cases; treat it as a performance hint, not a guarantee of identity for correctness. - With React Compiler 1.0 the compiler adds memoization automatically; for new code rely on it and use manual hooks as escape hatches (for example a stable effect dependency).
The red pen
Common traps: mistake → fix
Mistake: "useCallback makes functions faster"
Fix: it only keeps the same identity.
Mistake: "memo the child and the problem is solved"
Fix: inline object/function/children props break it.
Mistake: "Memoize every value"
Fix: cheap calculations cost more to memoize than to redo.
Easy to hard
Questions interviewers ask, easy to hard
- What is the difference between
React.memo,useMemoanduseCallback? - Implement
useCallbackusinguseMemo. - We wrapped
Rowinmemobut every row still re-renders. Why? - When does memoization make things slower?
- With the React Compiler enabled, do you still write these?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.