React · Lesson 113 of 120
Cheat Sheet: Hooks
The essentials.
Now the hooks. Each one has a single job. Here's when to reach for which.
- Hooks
- One job each
- Which one when
Core hooks
Use state remembers a value that's shown. Use reducer handles complex updates with actions. Use effect syncs with the outside world. Use ref remembers without re-rendering, or points at an element. And use context reads shared values.
| Hook | Job |
|---|---|
| useState | remember a shown value |
| useReducer | complex updates, actions |
| useEffect | sync with outside |
| useRef | no re-render, or an element |
| useContext | read shared values |
Performance and React 19
Use memo caches a slow calculation, and use callback a function. Use transition and use deferred value keep things responsive. Use action state runs form actions, use optimistic shows instant results, and use reads promises and context.
| Hook | Job |
|---|---|
| useMemo / useCallback | cache values / functions |
| useTransition | non urgent updates |
| useDeferredValue | a lagging copy |
| useActionState | form actions |
| useOptimistic | instant feedback |
| use | promises and context |
Summary
Every hook has one job. Pick the one that matches yours. Next, common patterns.
Key takeaways- State
- Effects
- Refs
Next up: Common Patterns — recipes