Redux Reference

Kip Landergren

(Updated: )

My cheat sheet for Redux covering terminology, helpful commands, and resources.

Contents

Redux Terminology

action
a message containing a “payload”
dispatch
function for passing actions to be processed by reducers
payload
the JavaScript object passed via an “action” which will be processed by the reducers
reducer
the function that accepts previous state and an action, returning a new state that, if needed, updates the store
slice
(Redux Toolkit) a convenience wrapper bundling a store, reducers, and actions; represents the entire stack of a specific segment of application state
slice
refers to a literal “slice” of data; can be thought of a way of segmenting state into multiple distinct pieces
store
an object containing a “plain JavaScript” object representing the state of the application

Commands

Create a new project:

$ npx create-react-app experiment-redux-todo --template redux

Redux Toolkit (RTK)

Async Thunks

Reducers should be pure: they should have no side effects. How should one then make requests or log data? Enter the thunk.

A “thunk” refers to deferred work, and “async” refers to the function’s execution context (asynchronous). An async thunk is just like a normal redux action but instead of an object is a function. This allows the function to be executed—in the async thunk case, asynchronously—and called with additional arguments. When created using createAsyncThunk there are a series of arguments—most importantly payloadCreator—that allow you to specify how this function behaves when processed by Redux middleware.

Best practices:

Keep in mind:

Entity Adapters / Reducers / Components

Best practices:

Resources

Understanding middleware and async actions: