On this page

05. Why Redux Toolkit Instead of Redux?

📄 Noteseasy#redux-toolkit#redux#boilerplate

Short answer

Redux Toolkit is the official, recommended way to write Redux. Classic Redux needed separate action types, action creators, switch-based reducers, hand-written immutable spreads and manual store setup. RTK removes that boilerplate with createSlice and configureStore, uses Immer for safe "mutating" updates, includes thunks and DevTools by default, and adds RTK Query for data fetching. Plain createStore is now marked deprecated.

Explanation

Classic Redux is like assembling furniture from raw wood: possible, but every team cuts the pieces differently and makes the same mistakes. RTK is the flat-pack kit with pre-drilled holes: same furniture, fewer screws, fewer ways to get it wrong.

Problems with classic Redux

  • Boilerplate: one feature meant constants file + actions file + reducer file.
  • Immutability bugs: deep spreads like {...state, a: {...state.a, b: {...}}} are easy to get wrong, and an accidental mutation silently breaks re-renders.
  • Store setup: wiring applyMiddleware, compose, DevTools extension and thunk by hand.
  • No opinion on async or data fetching: every team reinvented loading/error flags.

What RTK gives you

ConcernClassic ReduxRedux Toolkit
Store setupcreateStore + applyMiddleware + DevTools composeconfigureStore({ reducer })
ActionsManual type constants + creatorsGenerated by createSlice
Reducersswitch with spreadsObject of case reducers with Immer
AsyncInstall and wire redux-thunkcreateAsyncThunk, thunk included
Mutation detectionNoneDev-only immutability check
Normalized dataHand-writtencreateEntityAdapter
Data fetching/cachingDIYRTK Query
TypeScriptLots of manual typesTypes inferred from slices

It is still Redux: same store, same DevTools, same react-redux hooks. You can migrate one slice at a time.

Example

// Classic Redux
const ADD_TODO = "todos/add";
const addTodo = (text) => ({ type: ADD_TODO, payload: text });

function todosReducer(state = [], action) {
  switch (action.type) {
    case ADD_TODO:
      return [...state, { id: Date.now(), text: action.payload, done: false }];
    default:
      return state;
  }
}
// Redux Toolkit
import { createSlice, configureStore } from "@reduxjs/toolkit";

const todosSlice = createSlice({
  name: "todos",
  initialState: [],
  reducers: {
    addTodo: {
      reducer(state, action) {
        state.push(action.payload);
      },
      prepare(text) {
        return { payload: { id: crypto.randomUUID(), text, done: false } };
      },
    },
    toggleTodo(state, action) {
      const todo = state.find((t) => t.id === action.payload);
      if (todo) todo.done = !todo.done;
    },
  },
});

export const { addTodo, toggleTodo } = todosSlice.actions;
export const store = configureStore({ reducer: { todos: todosSlice.reducer } });

💡 Interview tip: Mention that the Redux team itself says "use RTK" in the official docs; it signals you follow current practice, not 2017 tutorials.

Common mistakes

  • Thinking RTK is a different library from Redux; it is Redux with official helpers.
  • Generating IDs or random values inside the reducer instead of in prepare (reducers must be pure).
  • Using createAsyncThunk for every API call when RTK Query would remove the slice entirely.
  • Assuming Immer means you can mutate state outside reducers.

Follow-up questions

  • Can you mix classic reducers with slices? Yes, configureStore accepts any reducer function, so migration is incremental.
  • Does Immer add a performance cost? A small one, negligible for typical state sizes; it can freeze and proxy large arrays, so avoid storing huge blobs.
  • When would you choose Zustand over RTK? For small apps that want minimal setup and do not need Redux DevTools workflows, middleware or RTK Query.

Quick recap

  • RTK is the official way to write Redux.
  • createSlice + configureStore cut boilerplate drastically.
  • Immer prevents accidental mutation bugs.
  • Thunks, DevTools, entity adapters and RTK Query come built in.