Redux Reference

Kip Landergren

(Updated: )

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

Contents

Terminology

action
1.

A message containing a “payload”

Related:

dispatch
1.

Function for passing actions to be processed by reducers.

Related:

payload
1.

The JavaScript object passed via an “action” which will be processed by the reducers.

Related:

reducer
1.

The function that accepts previous state and an action, returning a new state that, if needed, updates the store.

Related:

slice
1.

(Redux Toolkit) a convenience wrapper bundling a store, reducers, and actions; represents the entire stack of a specific segment of application state.

Related:

slice
1.

Refers to a literal “slice” of data; can be thought of a way of segmenting state into multiple distinct pieces.

Related:

store
1.

An object containing a “plain JavaScript” object representing the state of the application.

Related:

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: