Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
They help when they keep a value or function stable for a memoized child or an effect dependency, or skip a genuinely expensive calculation; otherwise they add cost and complexity.
useMemo caches a computed value and useCallback caches a function between renders until dependencies change. They pay off in three cases: skipping a calculation that is measurably slow, keeping a prop stable so a React.memo child can skip rendering, and keeping a dependency stable so an effect does not re-run. Wrapping cheap calculations or functions passed to plain DOM elements gains nothing and still costs a comparison on every render. Measure first with the Profiler, and note that the React Compiler can add much of this memoization automatically.