Reducers are responsible for handling the actions that are dispatched. They take in the existing state and every action, and return a new state based on that action.
We'll add a switch/case statement in the todos reducer to handle the add todo action, which will return a new todos state.
It's important to note that reducers should not modify the state, but only return a new state object; so we'll use the object and array spread operators.
Summary of Content:
- Reducers handle actions that come in - usually with a switch/case statement
- The state that comes into reducers is immutable, so we'll use the object spread operators to return a new state
- Once the reducer returns a new state, the TodoList will automatically re-render, because the props change