lesson
React Patterns & Performance
Hooks, state management, memoisation, and rendering optimisation.
React Patterns & Performance
Essential Hooks
| Hook | Purpose |
|---|---|
useState | Local component state |
useEffect | Side effects (API calls, subscriptions) |
useRef | Mutable reference that doesn't trigger re-render |
useMemo | Cache expensive computation results |
useCallback | Cache function references (for child prop stability) |
useReducer | Complex state logic (like a mini Redux) |
useContext | Read context values without prop drilling |
When to Memoise
Don't memoise everything. Only use useMemo/useCallback when:
React.memo childRendering Optimisation
Why Components Re-render
A component re-renders when:How to Prevent Unnecessary Re-renders
React.memo(Component) — skip re-render if props are shallowly equalState Management Decision Tree
Local state only? → useState / useReducer
Shared across siblings? → lift state to parent
Shared across distant components? → Context + useReducer
Global, complex, server-synced? → TanStack Query / SWR (for server state)
Global, complex, client-only? → Zustand / Jotai
Sign in to use the AI study buddy on this lesson.