State and forms
useState and updater functions, controlled inputs and validation, and lifting state up to share it.
About 5 hours of study
Learning objectives
- Keep and update state
- Build controlled forms
- Share state through a common parent
Lessons
- 1
State: a component's memory Intermediate
useState for values that change over time, why setting state makes React render again, state as a snapshot, updater functions, and keeping objects and arrays in state without changing them.
- 2
Forms and controlled inputs Intermediate
Controlled inputs that show state and update it on every keystroke, text fields, checkboxes and selects, handling submit, validating, and computing values from form state instead of storing them.
- 3
Sharing state between components Intermediate
Lifting state up to the closest common parent, passing values and setter callbacks down as props, keeping one source of truth, and choosing where each piece of state should live.
Module practice
- React: A counter that cannot go below zeroEasy
- React: A like buttonMedium
- React: A counter with steps and undoHard
- React: Mirror what is typedEasy
- React: Validate a sign-up formMedium
- React: A tip calculatorHard
- React: Counters that share a totalEasy
- React: Tabs with lifted stateMedium
- React: Two units, one source of truthHard
Module quiz
‹ Rendering data and respondingEffects, refs and custom Hooks ›