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.
The reducer is a pure function that takes the previous state and an action, and returns the next state. (previousState, action) => newState. It's called a reducer because it's the type of function you would pass to Array.
Reducers are functions that take the current state and an action as arguments, and return a new state result. In other words, (state, action) => newState .
A reducer is a function that determines changes to an application's state. It uses the action it receives to determine this change. We have tools, like Redux, that help manage an application's state changes in a single store so that they behave consistently.
In Redux, a reducer is a pure function that takes an action and the previous state of the application and returns the new state. The action describes what happened and it is the reducer's job to return the new state based on that action.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With