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
| Hook | Purpose | Key point |
|---|---|---|
useState / useReducer | Component state | A state update "requests the next render"; it doesn't change the variable immediately |
useEffect | Syncing with external systems (subscriptions, requests, DOM) | Dependency array; returns a cleanup function. Not for deriving data |
useMemo / useCallback | Cache a computed result / a function reference | Purely a performance optimization; must not affect correctness |
useRef | Hold mutable values that don't trigger renders, DOM references | |
useTransition / useDeferredValue | Mark updates as non-urgent to keep input responsive | Useful when filtering large lists |
use (React 19) | Read a Promise or Context during render | Works with Suspense |
useActionState / useOptimistic (React 19) | State for form Actions, optimistic updates | Pairs 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. keydetermines 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/memofor 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
- Missing Effect dependencies, or object dependencies that are a new reference every time → infinite request loops.
- Stale closures: timers / event callbacks read old state. Use a functional update
setX(x => x + 1)or a ref. - Using the index as key.
- Over-memoizing:
useMemoeverywhere adds complexity. Find the real bottleneck with the React DevTools Profiler first.
Common interview questions
- When a parent updates, does the child always re-render? How do you avoid it?
- What's the difference between
useEffectanduseLayoutEffect? When shouldn't you use an Effect? - What does a list
keydo? What's wrong with using the index? - What does React Compiler do? Do you still need to write
useMemoby hand? - What problem does
useTransitionsolve?
How it relates to my projects
- AI Document Review Pipeline: the task list (virtualized list +
useDeferredValuefor filtering) and the review form (useActionState+ optimistic updates).
Sources
- React Docs: Render and Commit
- React Docs: You Might Not Need an Effect
- React Docs: Hooks API Reference
- React Blog: React Compiler v1.0 (2025-10-07)
- React Blog: React 19 (2024-12-05) —
use, Actions,useActionState,useOptimistic
