Skip to content
Goal: 熟练使用 → 部分深入原理✓ Sources verified 2026-11-24React 19HooksReact Compiler

React: Hooks, Rendering and Performance ​

In admin-style pages such as a review console or task list, performance problems mostly come from unnecessary re-renders.

Core concepts ​

HookPurposeKey point
useState / useReducerComponent stateA state update "requests the next render"; it doesn't change the variable immediately
useEffectSyncing with external systems (subscriptions, requests, DOM)Dependency array; returns a cleanup function. Not for deriving data
useMemo / useCallbackCache a computed result / a function referencePurely a performance optimization; must not affect correctness
useRefHold mutable values that don't trigger renders, DOM references
useTransition / useDeferredValueMark updates as non-urgent to keep input responsiveUseful when filtering large lists
use (React 19)Read a Promise or Context during renderWorks with Suspense
useActionState / useOptimistic (React 19)State for form Actions, optimistic updatesPairs with Next.js Server Actions

How it works ​

What happens in one update ​

setState → scheduling → render phase (call component functions, get a new element tree, diff against the old tree: reconciliation)
        → commit phase (apply the differences to the DOM) → run effects
  • When a parent re-renders, all its children re-render by default (even if their props didn't change), unless you skip them with memo.
  • key determines a list item's identity: using the index as key misplaces state when items are inserted or reordered.

React Compiler (1.0 stable released 2025-10) ​

  • Automatically adds memoization to components and Hooks at build time, roughly equivalent to writing useMemo / useCallback / memo for you.
  • It requires code that follows the Rules of React (components are pure, no mutating external variables during render, etc.). An official ESLint rule checks this.
  • What it means: new projects need less manual memoization, but understanding why re-renders happen is still a key interview topic.

In practice ​

1. Don't derive data with an Effect ​

tsx
// ❌ an extra render, and easy to get out of sync
const [filtered, setFiltered] = useState([]);
useEffect(() => setFiltered(tasks.filter(t => t.status === status)), [tasks, status]);

// ✅ compute during render; use useMemo only if it's genuinely expensive
const filtered = useMemo(() => tasks.filter(t => t.status === status), [tasks, status]);

2. Push state down to shrink the re-render area ​

Keep "the input's value" inside the input component rather than at the top of the page, so each keystroke doesn't re-render the whole page.

3. Long lists ​

For task lists with thousands of rows, use a virtualized list (e.g. TanStack Virtual) that renders only the visible area.

Common pitfalls ​

  1. Missing Effect dependencies, or object dependencies that are a new reference every time → infinite request loops.
  2. Stale closures: timers / event callbacks read old state. Use a functional update setX(x => x + 1) or a ref.
  3. Using the index as key.
  4. Over-memoizing: useMemo everywhere adds complexity. Find the real bottleneck with the React DevTools Profiler first.

Common interview questions ​

  1. When a parent updates, does the child always re-render? How do you avoid it?
  2. What's the difference between useEffect and useLayoutEffect? When shouldn't you use an Effect?
  3. What does a list key do? What's wrong with using the index?
  4. What does React Compiler do? Do you still need to write useMemo by hand?
  5. What problem does useTransition solve?

How it relates to my projects ​

  • AI Document Review Pipeline: the task list (virtualized list + useDeferredValue for filtering) and the review form (useActionState + optimistic updates).

Sources ​

Vin Amory · AI development × content creation · Technical notes cite official docs in each page’s sources section