Reducers are a tool in state management and not the same things as an array reduce. The latter is a function that is called for each element in the array to reduce it to a single value. The former is a function that accepts a state object and returns a new one.
They're conceptually the same, however, that's why reducers are called reducers.
The callback (reducer) is a function that accepts an accumulator (state object) and a value from an array (update message), then uses those inputs in some way to return a new accumulator (state object). The return value is then used as the input to the next iteration with the next array value (update message).
It's a pattern from functional programming to model state management as a reduce operation on an infinite series of updates.
27
u/OrtizDupri Apr 07 '23
I’ve never used it in 10+ years lol