Before we learn how to make generic abstractions for our reducers, we will take a closer look at pure functions. We have already learned a bit about them in the previous chapters. Pure functions have no side effects; they always return the same output, given the same input. The following is what makes Redux so predictable:
- Reducers take the current state and an action and return the new state
- All reducers are pure functions
- Given the same input, pure functions return the same output
- As a result, given the same state and action, reducers will always return the same new state
When writing abstractions on top of our reducers, we need to make sure that they are also pure functions, otherwise we will lose the benefits of Redux and introduce unpredictable behavior.