Create a Reducer Function for Multiple Redux Actions using redux-actions

InstructorAndy Van Slaars

Share this video with your friends

Send Tweet

We're using the reduced reducers library to take these individual reducers that we've created with handle action and combine them into a single reducer. This is a fairly common need.

In this lesson, we’ll use the handleActions function provided by redux-actions to create a reducer that will handle multiple actions, using a reducerMap.

Saeid
Saeid
~ 3 years ago

Nice. I like it. thanks!

pestlett
pestlett
~ 3 years ago

There is a bug in the createActions section of the code. For example you use "REMOVE_TODO" as the key rather than the constant REMOVE_TODO, that is used in the actions. If you updated the const REMOVE_TODO value, then the code would break

Viktor Soroka
Viktor Soroka
~ 2 years ago

There is a bug in the createActions section of the code. For example you use "REMOVE_TODO" as the key rather than the constant REMOVE_TODO, that is used in the actions. If you updated the const REMOVE_TODO value, then the code would break

You could use computed property as Andy used for [combineActions(SHOW_LOADER, HIDE_LOADER)].

Dean
Dean
~ 2 years ago

Great explanations & communication - natural teacher... BUT, for "handleActions", I can't see what the "big payoff is". You just subbed an object map for a switch statement, and ended up with more code. I don't see what the cognitive load here you are trying to remove. I liked the separation and usage of reduceReducer more as it was a clear separation, and easier to reason about. Of course, that "extra" step of combing the reducers is used.. overall, please help me understand what the big gain is here using handleActions?

Andy Van Slaars
Andy Van Slaars(instructor)
~ 2 years ago

Dean,

No “big payoff”. If you think a different approach is more readable, then you should do it. I like the object map and having the reduceReducers call encapsulated in the handleActions function, but it’s important that you and your team are comfortable with whatever approach you take in your code, so if that means keeping the separation and combining the reducers yourself, there’s nothing wrong with that.