Redux Cheatsheet - State Management
This reference is for React developers who want predictable, central state with the Redux Toolkit. It covers store configuration, createSlice with its auto-generated actions and Immer-powered immutability, async logic via createAsyncThunk with pending/fulfilled/rejected cases, middleware, and the React bindings useSelector/useDispatch. A closing section shows normalized state with createEntityAdapter and a first look at RTK Query. After reading you should be able to set up a slice, dispatch both sync and async actions, read state reactively, and model collections as normalized entities.
Store Setup 5
const store = configureStore({ reducer: rootReducer })configureStore({ reducer: { users: usersReducer, posts: postsReducer } })configureStore({ middleware: (gdm) => gdm().concat(logger) })configureStore({ devTools: process.env.NODE_ENV !== "production" })const rootReducer = combineReducers({ users, posts })Slice Creation 6
const slice = createSlice({ name, initialState, reducers })name: "counter"initialState: { count: 0 }reducers: { increment(state) { state.count += 1 } }extraReducers: (builder) => builder.addCase(fulfilled, ...)export const { increment } = slice.actionsActions & Dispatch 5
dispatch(increment())dispatch(fetchUser(id))const { increment } = counterSlice.actionsstore.dispatch({ type: "counter/increment" })export default slice.reducerAsync Handling 5
const fetchUser = createAsyncThunk("user/fetch", async (id) => {})builder.addCase(fetchUser.pending, (state) => {})builder.addCase(fetchUser.fulfilled, (state, action) => {})builder.addCase(fetchUser.rejected, (state, action) => {})await dispatch(fetchUser(id)).unwrap()Middleware 5
const logger = () => (next) => (action) => {}middleware: (gdm) => gdm().concat(customMiddleware)configureStore({ middleware: (gdm) => gdm({ serializableCheck: false }) })import { thunk } from "redux-thunk"gdm({ immutableCheck: false, serializableCheck: false })Selectors 5
useSelector((state) => state.counter.value)const dispatch = useDispatch()const selectCount = (state) => state.counter.valueconst selectUserById = createSelector(...)useSelector(selectUserById, shallowEqual)Common Patterns 6
<Provider store={store}><App /></Provider>state.entities[id]createEntityAdapter({ selectId: (item) => item.id })adapter.getSelectors((state) => state.items)adapter.upsertOne(state, item)import { createApi } from "@reduxjs/toolkit/query/react"Tips
- Redux three principles: single source of truth, state is read-only, changes via pure functions.
- RTK bundles Immer, so you can 'mutate' state directly in reducers; it generates immutable updates.
- useSelector re-runs on store updates; returning a new reference triggers a re-render, so watch performance.
- Redux Toolkit (RTK) is the official recommended way; configureStore and createSlice cut boilerplate.
- createAsyncThunk with extraReducers handles async; redux-thunk is bundled in RTK's default middleware.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us