Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
88
rated 0 times [  95] [ 7]  / answers: 1 / hits: 21818  / 9 Years ago, sat, december 19, 2015, 12:00:00

This is a part the official Redux documentation:




It’s called a reducer because it’s the type of function you would pass
to Array.prototype.reduce(reducer, ?initialValue)




It doesn't make much sense to me. Could somebody explain to me why they are actually called reducers? The fact that they return a default value (or they have a default argument value) doesn't make them reducers IMHO.


More From » redux

 Answers
28

The fact that they return a default value (or they have a default
argument value) doesn't make them reducers IMHO.




Reducers do not just return default values. They always return the accumulation of the state (based on all previous and current actions).



Therefore, they act as a reducer of state. Each time a redux reducer is called, the state is passed in with the action (state, action). This state is then reduced (or accumulated) based on the action, and then the next state is returned. This is one cycle of the classic fold or reduce function.



As @azium summed up with state -> action -> state.


[#64011] Wednesday, December 16, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
braydon

Total Points: 0
Total Questions: 102
Total Answers: 111

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
;