Redux Toolkit vs Plain Redux: Key Differences and When to Use Each
Redux Toolkit simplifies Redux by reducing boilerplate and providing built-in tools like createSlice and configureStore. Plain Redux requires more manual setup and verbose code but offers full control over state management.Quick Comparison
This table summarizes the main differences between Redux Toolkit and Plain Redux.
| Factor | Redux Toolkit | Plain Redux |
|---|---|---|
| Setup Complexity | Simple with built-in defaults | Manual and verbose setup |
| Boilerplate Code | Minimal, uses createSlice | High, needs action types and creators |
| Learning Curve | Easier for beginners | Steeper due to manual patterns |
| Code Size | Smaller and cleaner | Larger and repetitive |
| Built-in Features | Includes immer, redux-thunk | Requires manual integration |
| Flexibility | Good for most apps | Full control for custom needs |
Key Differences
Redux Toolkit is designed to make Redux easier and faster to use by providing a set of tools that handle common tasks automatically. It uses createSlice to combine reducers and actions in one place, reducing the need to write action types and creators manually. It also includes configureStore which sets up the store with good defaults like middleware and DevTools support.
In contrast, Plain Redux requires you to write action types, action creators, and reducers separately. You must manually set up the store and add middleware like redux-thunk if needed. This approach gives you full control but results in more code and complexity.
Because Redux Toolkit uses immer internally, you can write simpler reducer logic that looks like direct state mutation but is actually immutable. Plain Redux requires careful immutable updates, which can be error-prone for beginners.
Code Comparison
Here is how you create a simple counter with increment and decrement actions using Plain Redux.
import { createStore } from 'redux'; // Action types const INCREMENT = 'INCREMENT'; const DECREMENT = 'DECREMENT'; // Action creators const increment = () => ({ type: INCREMENT }); const decrement = () => ({ type: DECREMENT }); // Reducer function counterReducer(state = { value: 0 }, action) { switch (action.type) { case INCREMENT: return { value: state.value + 1 }; case DECREMENT: return { value: state.value - 1 }; default: return state; } } // Store const store = createStore(counterReducer); // Usage store.dispatch(increment()); store.dispatch(increment()); store.dispatch(decrement()); console.log(store.getState());
Redux Toolkit Equivalent
The same counter example using Redux Toolkit is much shorter and clearer.
import { configureStore, createSlice } from '@reduxjs/toolkit'; const counterSlice = createSlice({ name: 'counter', initialState: { value: 0 }, reducers: { increment(state) { state.value += 1; }, decrement(state) { state.value -= 1; } } }); const store = configureStore({ reducer: counterSlice.reducer }); store.dispatch(counterSlice.actions.increment()); store.dispatch(counterSlice.actions.increment()); store.dispatch(counterSlice.actions.decrement()); console.log(store.getState());
When to Use Which
Choose Redux Toolkit when you want faster development, less boilerplate, and easier state management with good defaults. It is ideal for most React apps and beginners because it simplifies Redux patterns and reduces errors.
Choose Plain Redux if you need full control over every part of your state logic or want to learn Redux fundamentals deeply. It can be useful in complex or legacy projects where custom setups are required.