0
0
ReactComparisonBeginner · 4 min read

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.

FactorRedux ToolkitPlain Redux
Setup ComplexitySimple with built-in defaultsManual and verbose setup
Boilerplate CodeMinimal, uses createSliceHigh, needs action types and creators
Learning CurveEasier for beginnersSteeper due to manual patterns
Code SizeSmaller and cleanerLarger and repetitive
Built-in FeaturesIncludes immer, redux-thunkRequires manual integration
FlexibilityGood for most appsFull 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.

javascript
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());
Output
{ value: 1 }
↔️

Redux Toolkit Equivalent

The same counter example using Redux Toolkit is much shorter and clearer.

javascript
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());
Output
{ value: 1 }
🎯

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.

Key Takeaways

Redux Toolkit reduces boilerplate and simplifies Redux setup with built-in tools.
Plain Redux requires manual action and reducer setup but offers full control.
Redux Toolkit uses immer for simpler immutable updates in reducers.
Choose Redux Toolkit for most apps and beginners for faster, cleaner code.
Use Plain Redux when you need custom control or are maintaining legacy code.