Handling Responses to Actions in the Reducer
In Redux, all actions pass through the reducer. Surely, the reducer must have a way to differentiate between different actions. Let's find out.
Now that you successfully understand what an action is, it is important to see how they become useful i.e in a practical sense.
Earlier, I did say that a reducer takes in two arguments. One, state, the other, action. Here’s what a simple Reducer looks like:
function reducer(state, action) {
//return new state
}
The action is passed in as the second parameter to the Reducer, however, we’ve done nothing with it within the function itself.
To handle the actions passed into the reducer, you typically write a switch statement within your reducer, like this:
Get hands-on with 1200+ tech skills courses.