Redux Toolkit
Redux Toolkit (RTK) is the official, opinionated toolset for writing Redux logic, bundling store setup, reducer creation, immutable update helpers, and data-fetching utilities to eliminate the boilerplate historically associated with plain…
Definition
Redux Toolkit (RTK) is the official, opinionated toolset for writing Redux logic, bundling store setup, reducer creation, immutable update helpers, and data-fetching utilities to eliminate the boilerplate historically associated with plain Redux.
Overview
Redux itself is a predictable state container based on a single store, pure reducer functions, and dispatched actions, but writing idiomatic Redux by hand required substantial boilerplate: action type constants, action creators, switch-statement reducers, and manual immutability. Redux Toolkit was released by the Redux maintainers to codify best practices into a small set of APIs, most notably `configureStore` (which sets up the store with sensible defaults like Redux DevTools and thunk middleware) and `createSlice` (which generates action creators and a reducer from a single object describing state and "mutating" update logic). Under the hood, `createSlice` uses the Immer library so developers can write reducers that appear to mutate state directly — `state.count += 1` — while Immer produces a properly immutable update behind the scenes. This removes one of the most common sources of bugs in classic Redux code: accidental direct mutation or verbose spread-operator immutability code. RTK also ships RTK Query, a data-fetching and caching layer comparable to React Query, which generates hooks for API endpoints, handles caching, invalidation, and loading/error states, and integrates directly into the Redux store. This lets teams standardize both client state and server-state caching within one library rather than combining Redux with a separate fetching library. Because Redux Toolkit is the officially recommended way to use Redux, most new Redux applications since its release use RTK by default rather than assembling Redux from its lower-level primitives, and the Redux documentation itself is written RTK-first.
Key Features
- `configureStore` sets up a Redux store with sensible defaults and DevTools integration
- `createSlice` generates action creators and reducers from a single configuration object
- Uses Immer internally to allow "mutating" syntax that produces immutable updates
- Built-in `createAsyncThunk` for standardized async action handling
- RTK Query provides data fetching, caching, and invalidation out of the box
- Includes default middleware for serializability and immutability checks in development
- TypeScript-first API design with strong type inference
- Officially maintained and recommended by the Redux core team