React Cheat Sheets
Visual quick-reference cards for React concepts. Screenshot-ready for your notes app, Notion, or next interview prep session.
React Hooks Reference
When to use each hook, the signature, and the gotcha that trips people up
useStateconst [value, setValue] = useState(initial)Use when
Local component state that triggers re-renders
Never mutate directly — always return new values
useEffectuseEffect(() => { ... return cleanup }, [deps])Use when
Sync with external systems (APIs, subscriptions, timers)
[] = mount only · [x] = when x changes · no array = every render
useRefconst ref = useRef(initialValue)Use when
DOM access, mutable values that don't trigger re-renders
Mutating ref.current does NOT cause a re-render
useMemoconst result = useMemo(() => compute(a, b), [a, b])Use when
Cache an expensive computed value between renders
Only helps if compute is actually expensive (>1ms)
useCallbackconst fn = useCallback(() => { ... }, [deps])Use when
Stable function reference for React.memo children
Only helps when passed to a memoized child
useContextconst value = useContext(MyContext)Use when
Read context value — re-renders when context changes
Split contexts by update frequency to avoid over-rendering
useReducerconst [state, dispatch] = useReducer(reducer, init)Use when
Complex state with multiple transitions or related sub-values
dispatch is always stable — safe as useEffect dependency
useIdconst id = useId()Use when
Generate unique, stable IDs for accessibility (labels, ARIA)
Never use as list key — IDs are stable across renders
useTransitionconst [isPending, startTransition] = useTransition()Use when
Mark a state update as non-urgent (keeps UI responsive)
Only in React 18+. State inside startTransition is interruptible
Component Lifecycle (Functional)
What happens at each phase and which hooks correspond to each stage
useLayoutEffect3. useLayoutEffectuseEffect5. useEffectreturn () =>4. useEffect cleanupuseEffect5. useEffectreturn () =>1. useLayoutEffect cleanupreturn () =>2. useEffect cleanupState Management Decision Tree
Follow this to always pick the right state solution
Is the data fetched from a server?
Does only ONE component need this data?
Do 2–3 nearby sibling components need it?
Is it app-wide config (theme, auth, locale)?
Complex UI state shared across many components?
Interview Flash Cards
Common interview questions — screenshot and use for quick review
Virtual DOM vs Real DOM
CoreVirtual 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
FormsControlled: input value driven by React state. Uncontrolled: input stores value in the DOM, accessed via ref.
Why immutable state?
StateReact 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
PerformanceReact.memo memoizes a component (skips re-render if props unchanged). useMemo memoizes a value inside a component.
Key prop rule
ListsUse 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
HooksuseEffect: async, after browser paint. useLayoutEffect: sync, before paint. Use useLayoutEffect only for DOM measurement or preventing visual flicker.
When to use Context?
ContextFor 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?
Core1. Own state changes. 2. Parent re-renders (if not memoized). 3. Consumed context changes. Regular variable changes do NOT trigger re-renders.
Error Boundary
PatternsClass component that catches JS errors in its subtree. Renders fallback UI instead of crashing. Requires getDerivedStateFromError + componentDidCatch.
Performance Quick Reference
Match the symptom to the solution — always profile before optimising
| Problem / Symptom | Tool / Fix |
|---|---|
| Child re-renders when parent does | React.memo |
| Callback prop breaks React.memo | useCallback |
| Object prop breaks React.memo | useMemo |
| Expensive computation on every render | useMemo |
| 100+ item list is slow | @tanstack/react-virtual |
| Context re-renders too many components | Split contexts |
| Typing input lags during heavy render | useTransition / useDeferredValue |
| Slow initial page load | React.lazy + Suspense |
| Can't tell what's slow | React DevTools Profiler |