Concept
useReducer manages state through a reducer function that maps the current state and an action to the next state. It keeps related updates in one place and makes complex transitions testable.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show useReducer doing its job.
type Action = { type: "add"; text: string } | { type: "toggle"; id: number };
function reducer(todos: Todo[], action: Action): Todo[] {
switch (action.type) {
case "add": return [...todos, { id: Date.now(), text: action.text, done: false }];
case "toggle": return todos.map((t) => t.id === action.id ? { ...t, done: !t.done } : t);
}
}
const [todos, dispatch] = useReducer(reducer, []);
dispatch({ type: "add", text: "Write tests" });Mutating the state inside the reducer and returning it. React compares by reference, sees the same object, and skips the render. Always return a new state object.
Your roadmap puts these before useReducer, unless you already know them.
Once a session shows you understand useReducer, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.