Chapter 8. Redux

Redux has emerged as one of the clear winners in the field of Flux or Flux-like libraries. Redux is based on Flux, and it was designed to tackle the challenge of understanding how data changes flow through your application. Redux was developed by Dan Abramov and Andrew Clark. Since creating Redux, both have been hired by Facebook to work on the React team.

Andrew Clark was working on version 4 of Flummox, another Flux-based library, when he started assisting Dan with the task of completing Redux. The message on the npm page for Flummox reads:

Eventually 4.x should be the last major release but it never happened. If you want the latest features, then use Redux instead. It’s really great.1

Redux is surprisingly small, only 99 lines of code.

We have mentioned that Redux is Flux-like, but it is not exactly Flux. It has actions, action creators, a store, and action objects that are used to change state. Redux simplifies the concepts of Flux a bit by removing the dispatcher, and representing application state with a single immutable object. Redux also introduces reducers, which are not a part of the Flux pattern. Reducers are pure functions that return a new state based on the current state and an action: (state, action) => newState.

State

The idea of storing state in one place isn’t so crazy. In fact, we did it in the last chapter. We stored it in the root of our application. In pure React or Flux apps, storing state in as few objects as possible is recommended. ...

Get Learning React now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.