Quick reference for essential React Hooks with common pattern and usage example.
useState
Local component state that persist between re-render and triggers updates when changes.
Basic API
Immutable updates
Always create new objects and arrays instead of mutating state.
Updater functions
Use function for dependent updates to avoid stale state.
Deriving state
Calculate values during render instead storing them in state.
State organization
Structure state to avoid contradictions and duplication. Group related state that changes together.
Resetting state
Use key props to reset component state when data changes.
Updates Batched: Multiple setState calls in events are batched automatically
Stale Closure: Use adapter functions to avoid stale state
useContext
Share data across component tree without manually passing props through every level.
Basic API
Sharing and updating data
Create context, provide values, and consume anywhere in component tree.
No props drilling: skip intermediate component entirely
Single Source: Context value comes from nearest Provider above
useEffect
Escape hatch too syncronize with external systems and perform side effect after render.
Basic API
Event listeners
Subscribe to DOM event and cleanup on unmount.
External connections
Connect to external system and cleanup when done.
After render: Effect run after DOM updates, not during
Cleanup required: Always cleanup subscriptions and timers
useRef
Escape hatch for mutable value and DOM references that persist across renders without re-rendering.
Basic API
DOM manipulation
Access DOM nodes imperative operations.
Mutable values
Store value that persist across renders without triggering re-renders.
No re-render: Changing ref.current doesn't trigger updates
Imperative API: Focus, scroll, play/pause, measurement
Instance variable: Store times, subscriptions,previous values
Custom Hooks
Extract and reuse stateful logic between components with functions starting with "use".
State logic
Each component gets its own independent state.
Start with "use": Naming convention enables linter rule
Composition: Build complex Hooks from simple Hooks