InterviewBuddy
All interview questions

When does memoization help in React?

Advanced

Answer

Memoization helps when a measured expensive calculation or unnecessary child render occurs with unchanged inputs. It trades memory and comparison work for potentially less computation.

Explanation

React.memo, useMemo, and useCallback solve different problems. They are performance tools, not correctness tools; profile first.

Example

const result = useMemo(() => expensive(items), [items]);