ConfigsApr 14, 2026·3 min read

Redux Toolkit — The Official Modern Way to Write Redux Logic

Redux Toolkit is the official, opinionated, batteries-included toolset for efficient Redux development. It eliminates boilerplate with createSlice, handles immutability with Immer, and includes RTK Query for API caching.

TL;DR
Redux Toolkit eliminates Redux boilerplate with createSlice, handles immutability via Immer, and includes RTK Query for API caching.
§01

What it is

Redux Toolkit (RTK) is the official, opinionated, batteries-included toolset for efficient Redux development. It eliminates the boilerplate that made Redux painful: no more hand-written action creators, action types, or switch-case reducers. createSlice generates all of these from a single configuration object, and Immer handles immutability under the hood.

It targets React developers who use Redux for state management and want to write less code with fewer bugs. It is also suitable for teams migrating from legacy Redux codebases.

§02

How it saves time or tokens

Traditional Redux requires writing action type constants, action creator functions, and reducer switch statements separately. RTK's createSlice reduces this to a single object with a name, initial state, and reducer functions. RTK Query replaces hand-written API fetching logic (thunks, loading states, caching) with a declarative API definition. A typical Redux feature that took 4 files now fits in 1.

§03

How to use

  1. Install Redux Toolkit: npm install @reduxjs/toolkit react-redux.
  2. Create a slice with createSlice() that defines state shape and reducers.
  3. Configure the store with configureStore() and provide it to your React app.
§04

Example

import { createSlice, configureStore } from '@reduxjs/toolkit'

const counterSlice = createSlice({
  name: 'counter',
  initialState: { value: 0 },
  reducers: {
    increment: (state) => { state.value += 1 },
    decrement: (state) => { state.value -= 1 },
    addAmount: (state, action) => { state.value += action.payload },
  },
})

export const { increment, decrement, addAmount } = counterSlice.actions

const store = configureStore({
  reducer: { counter: counterSlice.reducer },
})
§05

Related on TokRepo

§06

Common pitfalls

  • Immer's 'mutative' syntax in createSlice only works inside reducer functions. Writing state.value = x outside a reducer mutates state directly and causes bugs.
  • RTK Query cache invalidation requires proper tag definitions. Without tags, cached data can become stale without automatic refetching.
  • Migrating a large legacy Redux codebase to RTK should be incremental. Convert one slice at a time rather than rewriting everything at once.

Frequently Asked Questions

Is Redux Toolkit the recommended way to use Redux?+

Yes. The Redux team officially recommends Redux Toolkit for all new Redux code. The legacy createStore API is deprecated. RTK's configureStore and createSlice are the standard approach for Redux development.

What is RTK Query?+

RTK Query is a data fetching and caching layer built into Redux Toolkit. You define API endpoints declaratively, and RTK Query handles fetching, caching, refetching, loading/error states, and cache invalidation. It eliminates the need for manual thunks and loading state management.

Can I use Redux Toolkit with TypeScript?+

Yes. RTK has excellent TypeScript support with strong type inference. createSlice automatically infers action types and payload types. configureStore infers the root state type. The Redux team provides comprehensive TypeScript usage guides.

How does Immer work in Redux Toolkit?+

Immer lets you write code that appears to mutate state directly (state.value = 5) but actually produces a new immutable state object. RTK uses Immer inside createSlice reducers, so you get immutability guarantees without manually spreading state objects.

Should I use Redux Toolkit or Zustand?+

RTK is better for large applications with complex state, normalized data, or teams already using Redux. Zustand is lighter and simpler for small-to-medium apps. RTK Query gives Redux an advantage for applications with significant API interaction and caching needs.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets