Skip to content

Module 05 Recap

Module 05 covered computing values from state efficiently, caching expensive computations, stabilizing function references, and preventing unnecessary re-renders. Here is a summary.

Derive state instead of storing it. Any value computable from existing state should be a plain variable during render — not a useState. Removing duplicate state eliminates synchronization bugs.

useMemo caches expensive computations. Pass a compute function and a dependency array. The result is recalculated only when dependencies change. Use it for large dataset computations and values passed to memoized children — not for simple arithmetic.

useCallback stabilizes function references. A memoized child that receives a new function reference every render will still re-render. useCallback keeps the reference stable so React.memo can do its job.

React.memo skips renders when props are unchanged. It compares props by reference. For it to work, all object and function props must be stabilized with useMemo and useCallback.

Measure before optimizing. The React DevTools Profiler shows which components render, how often, and how long. Apply optimization only where you measure a real cost.

TermMeaning
Derived stateA value computed from existing state — no useState needed
useMemoCaches a computed value; recalculates only when dependencies change
useCallbackCaches a function reference; prevents unnecessary re-renders in memoized children
React.memoWraps a component to skip re-renders when props have not changed
Memoization triadReact.memo + useCallback + useMemo working together

Module 06 — Custom Hooks and Context — covers extracting component logic into reusable custom hooks and sharing state across the component tree without prop drilling. You will pull ZeroBudget’s entire state layer out of App.jsx into a useBudget hook and expose it through a BudgetContext.

Continue to Module 06 →