Question presented to candidate:
"What does React.memo do, and when is wrapping a component in it actually worth it?"
What a strong answer should cover:
memois a higher-order component that skips re-rendering when the new props are shallow-equal to the previous ones.- It compares props with
Object.isper key — shallow, not deep. - The bail-out is not a guarantee: React may still re-render, and state or context changes inside the component always re-render it regardless.
- The critical failure mode: an inline object, array, or function prop is a new reference every render, so
memonever bails. - Fixing that means
useMemo/useCallbackon the parent side — which is whymemorarely works alone. - The custom comparator second argument, and why it is usually a smell.
- When it is worth it: an expensive subtree, re-rendered often, with stable props. All three conditions.
- When it is not: cheap components, props that change every render anyway, or a component that would be better restructured with composition.
- Forward-looking: the React Compiler makes most manual
memoredundant.
Clarifying questions expected:
- "Have we profiled it? Is this component actually the bottleneck?"
- "Are its props stable, or created inline in the parent?"
Code / implementation expected: Yes — memo plus the useCallback needed to make it actually work.