Day 4 of 14 30 minuseStateRe-renderingUpdating objects
Make components remember things with the useState hook. Learn how setting state triggers a re-render, why state updates aren't immediate, how to use updater functions, and how to update objects and arrays without mutating them.
By the end of today you can
- Add state to a component with useState
- Explain how a state change causes a re-render
- Use the updater form when the next state depends on the previous one
- Update objects and arrays in state without mutating them
- Follow the rules of hooks
What's inside
- 7 sections
- 3 diagrams and mind maps
- 5 code examples you can run
- 5-question quiz
- 1Your first state
- 2Why a plain variable doesn't work
- 3How a state update works
- 4State is a snapshot
- 5Several pieces of state
- 6Objects and arrays: never mutate
- 7The rules of hooks
Sign in free to read this lesson
Get the full lesson with diagrams, runnable code and the quiz. Your progress is saved across devices.
Sign in free