A practical comparison between legacy Redux and Redux Toolkit, showing how RTK cuts boilerplate and the key pitfalls to avoid when migrating.
If you have ever worked with Classic Redux, you know the drill: creating a simple counter or to-do list requires action types, action creators, switch statements, and careful spread operators (...state) just to avoid mutating state accidentally.
Redux Toolkit (RTK) is now the official, recommended way to write Redux logic. It solves the "boilerplate problem" while keeping Redux's predictable state architecture intact.
In this guide, we’ll compare Classic Redux and Redux Toolkit side-by-side with practical code examples, and highlight the key things you need to watch out for when migrating.
Setting up a store in legacy Redux meant manually combining reducers, applying middleware like redux-thunk, and configuring the Redux DevTools extension by hand.
import { createStore, combineReducers, applyMiddleware, compose } from 'redux'; import thunk from 'redux-thunk'; import counterReducer from './counterReducer'; const rootReducer = combineReducers({ counter: counterReducer, }); const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; const store = createStore(rootReducer, composeEnhancers(applyMiddleware(thunk))); With configureStore, DevTools, redux-thunk, and slice combination happen automatically out of the box.
import { configureStore } from '@reduxjs/toolkit'; import counterReducer from './counterSlice'; const store = configureStore({ reducer: { counter: counterReducer, }, }); In Classic Redux, updating a nested array or object meant writing action constants, action creators, and immutable update logic across multiple files.
// Action Types const ADD_TODO = 'todos/ADD_TODO'; const TOGGLE_TODO = 'todos/TOGGLE_TODO'; // Action Creators export const addTodo = (text) => ({ type: ADD_TODO, payload: { id: Date.now(), text } }); export const toggleTodo = (id) => ({ type: TOGGLE_TODO, payload: id }); // Reducer const initialState = []; export default function todosReducer(state = initialState, action) { switch (action.type) { case ADD_TODO: return [...state, { ...action.payload, completed: false }]; case TOGGLE_TODO: return state.map((todo) => todo.id === action.payload ? { ...todo, completed: !todo.completed } : todo ); default: return state; } } What to Watch Out For When Migrating to RTK
Switching to Redux Toolkit feels like magic, but there are a few important rules beginners often trip over:Don't Mix Direct Mutation with Returning a New State
Inside a createSlice reducer, Immer lets you either mutate the existing state draft or return a brand-new state object—never both in the same reducer.
// Wrong: Mutating state AND returning a value updateUser: (state, action) => { state.name = action.payload.name; return state; // Avoid doing both } // Right: Just mutate the draft updateUser: (state, action) => { state.name = action.payload.name; } Only Put Serializable Data in the Store
Redux Toolkit includes a strict serializability check by default. Storing non-serializable values like Promises, functions, Map/Set instances, or Date objects directly in your Redux state or actions will trigger console warnings. Always store timestamps as ISO strings or numbers instead.Keep Derived Data Out of Redux State
When refactoring legacy stores, avoid storing filtered or sorted arrays alongside your main list (e.g., having both todos and filteredTodos in state). Store only the raw data and filter criteria, then compute derived lists using selectors (createSelector).
