Redux Logic Flow — Crazy Simple Summary
There are countless lengthy and complex articles trying to describe Redux, but Redux itself is actually a simple library. It’s easy to get lost in the depth when all that’s needed is a dead simple example of the logic process to refer to. Thus, I created this crazy simple summary.
Redux: A library which holds and updates the entire state of the app in the simplest manner possible while also using the least amount of boilerplate code.
Actions: Plain object that is returned by a pure function with no side-effects. The action object contains the “type” and any necessary information to update the state. The object is sent to the store using dispatch(), and the store updates the state using the information contained in the action object. Actions describe that something happened.
Reducer: A pure function that takes the current state and action, and performs an update on the state. It returns the new state. Typically use a switch statement that reads the
Store: There is only one and it holds the entire state in a single object. Assign it to a variable using
createStore(combinedReducer). The store passes two arguments to the reducer — the previous state and the action.
- Interaction that requires an update
- Redux store calls the reducer
- The root reducer may combine the output of multiple reducers into a single state tree
- The Redux store saves the complete state tree returned by the root reducer
- The components are “subscribed” through the connect function and updated accordingly