On this page
05. Why Redux Toolkit Instead of Redux?
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
| Concern | Classic Redux | Redux Toolkit |
|---|---|---|
| Store setup | createStore + applyMiddleware + DevTools compose | configureStore({ reducer }) |
| Actions | Manual type constants + creators | Generated by createSlice |
| Reducers | switch with spreads | Object of case reducers with Immer |
| Async | Install and wire redux-thunk | createAsyncThunk, thunk included |
| Mutation detection | None | Dev-only immutability check |
| Normalized data | Hand-written | createEntityAdapter |
| Data fetching/caching | DIY | RTK Query |
| TypeScript | Lots of manual types | Types 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
createAsyncThunkfor 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,
configureStoreaccepts 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+configureStorecut boilerplate drastically.- Immer prevents accidental mutation bugs.
- Thunks, DevTools, entity adapters and RTK Query come built in.