Module 4 · State that scales Lesson 10 of 15
useReducer for state with rules
When several pieces of state change together, useReducer keeps the rules in one place: a function that takes the current state and an action and returns the next state. It is useState with a plan.
Worked example
dispatch({ type: 'added', item }) routes to one switch that decides how the list changes, instead of five scattered setState calls.
Your practice task
Convert a component with three related useState calls into one useReducer with three actions.
Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.
Key takeaway
When several pieces of state change together, useReducer keeps the rules in one place: a function that takes the current state and an action and returns the next state. It is useState with a plan.
Keep your place in this course
A free account saves which lessons you have finished and unlocks the certificate. The lesson itself stays free to read.
Create free account or sign inCourse complete
You finished every lesson.
Your certificate is ready, and the projects you built are the proof to attach to an application.
Almost there
15 lessons left of 15
Finish every lesson to unlock the certificate. Each one ends in a practice task — do them and the final project brief writes itself.