React Cheat Sheets

Visual quick-reference cards for React concepts. Screenshot-ready for your notes app, Notion, or next interview prep session.

Quick Reference

React Hooks Reference

When to use each hook, the signature, and the gotcha that trips people up

useState
const [value, setValue] = useState(initial)

Use when

Local component state that triggers re-renders

Never mutate directly — always return new values

useEffect
useEffect(() => { ... return cleanup }, [deps])

Use when

Sync with external systems (APIs, subscriptions, timers)

[] = mount only · [x] = when x changes · no array = every render

useRef
const ref = useRef(initialValue)

Use when

DOM access, mutable values that don't trigger re-renders

Mutating ref.current does NOT cause a re-render

useMemo
const result = useMemo(() => compute(a, b), [a, b])

Use when

Cache an expensive computed value between renders

Only helps if compute is actually expensive (>1ms)

useCallback
const fn = useCallback(() => { ... }, [deps])

Use when

Stable function reference for React.memo children

Only helps when passed to a memoized child

useContext
const value = useContext(MyContext)

Use when

Read context value — re-renders when context changes

Split contexts by update frequency to avoid over-rendering

useReducer
const [state, dispatch] = useReducer(reducer, init)

Use when

Complex state with multiple transitions or related sub-values

dispatch is always stable — safe as useEffect dependency

useId
const id = useId()

Use when

Generate unique, stable IDs for accessibility (labels, ARIA)

Never use as list key — IDs are stable across renders

useTransition
const [isPending, startTransition] = useTransition()

Use when

Mark a state update as non-urgent (keeps UI responsive)

Only in React 18+. State inside startTransition is interruptible

Lifecycle

Component Lifecycle (Functional)

What happens at each phase and which hooks correspond to each stage

Mount Phase
1. Render
2. Commit
useLayoutEffect3. useLayoutEffect
4. Paint
useEffect5. useEffect
Update Phase
Triggered by
1. Render
2. Diff
3. Commit
return () =>4. useEffect cleanup
useEffect5. useEffect
Unmount Phase
return () =>1. useLayoutEffect cleanup
return () =>2. useEffect cleanup
3. DOM removal
Decision Guide

State Management Decision Tree

Follow this to always pick the right state solution

1

Is the data fetched from a server?

YES →React Query / RTK Query
Server state: cached, auto-refetched, invalidated on mutation
2

Does only ONE component need this data?

YES →useState / useReducer
Keep it local — simplest solution
3

Do 2–3 nearby sibling components need it?

YES →Lift state up
Move to nearest common parent, pass as props
4

Is it app-wide config (theme, auth, locale)?

YES →React Context
Changes rarely, read by many, no complex updates
5

Complex UI state shared across many components?

YES →Zustand or Redux Toolkit
Rich update logic, DevTools, middleware needed
Interview Prep

Interview Flash Cards

Common interview questions — screenshot and use for quick review

Virtual DOM vs Real DOM

Core

Virtual DOM is a lightweight JS object tree. React diffs it against the previous version and applies only the minimal real DOM changes.

Controlled vs Uncontrolled

Forms

Controlled: input value driven by React state. Uncontrolled: input stores value in the DOM, accessed via ref.

Why immutable state?

State

React uses reference equality (===) to detect changes. Mutating in place keeps the same reference — React sees no change and skips the re-render.

React.memo vs useMemo

Performance

React.memo memoizes a component (skips re-render if props unchanged). useMemo memoizes a value inside a component.

Key prop rule

Lists

Use stable, unique IDs as keys. Never use array index for dynamic lists that can reorder or filter — it breaks re-render optimization.

useEffect vs useLayoutEffect

Hooks

useEffect: async, after browser paint. useLayoutEffect: sync, before paint. Use useLayoutEffect only for DOM measurement or preventing visual flicker.

When to use Context?

Context

For data many components need that changes rarely (theme, auth, locale). Not for frequently-updating state — it re-renders all consumers.

What triggers a re-render?

Core

1. Own state changes. 2. Parent re-renders (if not memoized). 3. Consumed context changes. Regular variable changes do NOT trigger re-renders.

Error Boundary

Patterns

Class component that catches JS errors in its subtree. Renders fallback UI instead of crashing. Requires getDerivedStateFromError + componentDidCatch.

Performance

Performance Quick Reference

Match the symptom to the solution — always profile before optimising

Problem / SymptomTool / Fix
Child re-renders when parent doesReact.memo
Callback prop breaks React.memouseCallback
Object prop breaks React.memouseMemo
Expensive computation on every renderuseMemo
100+ item list is slow@tanstack/react-virtual
Context re-renders too many componentsSplit contexts
Typing input lags during heavy renderuseTransition / useDeferredValue
Slow initial page loadReact.lazy + Suspense
Can't tell what's slowReact DevTools Profiler