Quick answer
Redux Toolkit is the official way to write Redux, and it removes most of the boilerplate that gave Redux its reputation. One function, createSlice, writes your actions and reducers together; configureStore sets up the store with sensible defaults. This post builds a shop orders store in plain Node.js, adds up real totals across three Pakistani cities, and fixes the quiet dispatch mistake that loses an order.
A small shop site starts simply: a cart in one component, a total in the header, an order list on another page. Each piece keeps its own state with useState, and that works for a while. Then the header total disagrees with the checkout total, and an order removed on one page still shows on another. The state is not complicated; it is scattered. That is when a shared store earns its place, and Redux Toolkit is the version of Redux that makes the store small enough to justify.
What I would check before using it
My first check is whether the state is genuinely shared. A value used by one component belongs in useState; moving it into a store adds indirection for nothing. When two distant components read and change the same value, like a cart total in the header and on the checkout page, a store starts to pay back. The React useEffect Explained: When to Use It and Skip It post covers the local-state side of the same question. My judgement: keep state local until components disagree.
My second check is how much async work the app does. Redux Toolkit handles async with createAsyncThunk and can cache server data with RTK Query, but if the app mostly fetches lists and shows them, a lighter fetching tool may fit better. The JavaScript Async/Await Explained: Write Cleaner Code post covers the promise mechanics underneath. Do not pick a store to solve a fetching problem.
My third check is the size of the state compared with the alternatives. For a small shared state, Zustand is simpler; the Zustand: React State Without the Boilerplate post builds the same kind of shop state with far less code. Redux Toolkit earns its place when the state grows past a handful of values, several developers touch it, and the debugging tools matter more than the line count.
My verdict, as judgement: use Redux Toolkit when shared state is real and async updates are common. The recommendation flips for a single component, where useState wins, or for a tiny shared state, where Zustand wins, or when the data is mostly fetched and rarely edited.
Six orders, one store, and the dispatch that did nothing
The demo is a shop orders store built with @reduxjs/toolkit 2.15.0 in plain Node.js, no browser, no React. The slice below holds an array of orders, with three actions: add one, remove one by id, and change a quantity. The reducers look like they mutate state directly, and that is the point: createSlice uses Immer, so the mutation becomes a new state behind the scenes. Two selectors sit next to the slice and own all the maths.
const { configureStore, createSlice } = require('@reduxjs/toolkit');
const ordersSlice = createSlice({
name: 'orders',
initialState: [],
reducers: {
addOrder(state, action) {
state.push(action.payload);
},
removeOrder(state, action) {
return state.filter((order) => order.id !== action.payload);
},
updateQuantity(state, action) {
const order = state.find((o) => o.id === action.payload.id);
if (order) {
order.qty = action.payload.qty;
}
},
},
});
const { addOrder, removeOrder, updateQuantity } = ordersSlice.actions;
const store = configureStore({ reducer: { orders: ordersSlice.reducer } });
const selectTotalsByCity = (state) => {
const totals = {};
for (const order of state.orders) {
totals[order.city] = (totals[order.city] || 0) + order.qty * order.unitPrice;
}
return totals;
};
const selectGrandTotal = (state) =>
Object.values(selectTotalsByCity(state)).reduce((a, b) => a + b, 0);
Six orders go in, two in each of Karachi, Lahore, and Islamabad. Each has a quantity and a unit price, and the totals come from the selectors, not from the post. In a real app these orders would arrive from an API like the one in the Elysia Bun Tutorial: Build a Real Orders API for Shops post.
const seed = [
{ id: 1, customer: 'Sana', city: 'Karachi', item: 'Wireless headphones', qty: 2, unitPrice: 6250 },
{ id: 2, customer: 'Hamza', city: 'Karachi', item: 'USB-C cable pack', qty: 1, unitPrice: 8300 },
{ id: 3, customer: 'Daniyal', city: 'Lahore', item: 'Mechanical keyboard', qty: 1, unitPrice: 15400 },
{ id: 4, customer: 'Ayesha', city: 'Lahore', item: 'Laptop stand', qty: 2, unitPrice: 4850 },
{ id: 5, customer: 'Mahnoor', city: 'Islamabad', item: 'Webcam', qty: 1, unitPrice: 11200 },
{ id: 6, customer: 'Bilal', city: 'Islamabad', item: 'Mouse', qty: 2, unitPrice: 3400 },
];
for (const order of seed) {
store.dispatch(addOrder(order));
}
Totals after six orders:
Karachi: Rs 20800
Lahore: Rs 25100
Islamabad: Rs 18000
Grand total: Rs 63900
Orders in the store: 6
Then the demo goes wrong on purpose. The line store.dispatch(addOrder) passes the action creator itself instead of calling it. Redux Toolkit prints a warning, and the count proves nothing changed:
Detected an action creator with type "orders/addOrder" being dispatched.
Make sure you're calling the action creator before dispatching, i.e. `dispatch(addOrder())` instead of `dispatch(addOrder)`. This is necessary even if the action has no payload.
After dispatch(addOrder) with no call:
Orders in the store: 6
The fix is to call the creator, then dispatch what it returns. Zara's power bank lands in Karachi, the store holds seven orders, and the totals move to Rs 25,300 for Karachi and Rs 68,400 overall. The last two lines change a quantity and remove an order:
store.dispatch(
addOrder({ id: 7, customer: 'Zara', city: 'Karachi', item: 'Power bank', qty: 1, unitPrice: 4500 })
);
store.dispatch(updateQuantity({ id: 1, qty: 3 }));
store.dispatch(removeOrder(2));
Totals after adding Zara:
Karachi: Rs 25300
Lahore: Rs 25100
Islamabad: Rs 18000
Grand total: Rs 68400
Totals after Sana changes quantity to 3:
Karachi: Rs 31550
Lahore: Rs 25100
Islamabad: Rs 18000
Grand total: Rs 74650
Totals after removing Hamza:
Karachi: Rs 23250
Lahore: Rs 25100
Islamabad: Rs 18000
Grand total: Rs 66350
Orders in the store: 6
Final totals: Karachi Rs 23,250, Lahore Rs 25,100, Islamabad Rs 18,000, a grand total of Rs 66,350, with six orders left in the store. Every number above came from running the code.
Common mistakes and how to fix them
First, dispatching an action creator without calling it. The symptom is an order that never appears, plus a console warning naming the action type. The fix is dispatch(addOrder({...})), with the call and a payload.
Second, reassigning state inside a reducer. Writing state = state.filter(...) looks right, but Immer ignores the assignment, so both orders stay after a remove. The fix is to return the new array instead, or mutate the draft with splice.
Third, mutating the draft and returning a new value in the same reducer. Immer throws "[Immer] An immer producer returned a new value and modified its draft. Either return a new value or modify the draft." The fix is to pick one, never both.
Fourth, changing store state directly outside a reducer. Pushing into store.getState().orders throws "Cannot add property 1, object is not extensible" because that state is frozen. The fix is to dispatch an action and let the reducer make the change.
Frequently Asked Questions
Is Redux Toolkit the same as Redux? Yes, it is the official way to write Redux, not a replacement for it. The store, actions, and reducers are still Redux; Toolkit writes the repetitive parts for you.
Do I need Redux Toolkit for a small app? Probably not. One component's state belongs in useState, and a small shared state is simpler in Zustand. Reach for Toolkit when several components share state that changes often.
What does createSlice replace? It replaces hand-written action types, action creators, and switch statements. One call defines the state, reducers, and actions together, and the action creators it returns are ready to dispatch.
Can I use Redux Toolkit without React? Yes. This post runs it in plain Node.js with no React at all. The React binding is a separate package, react-redux.
What to remember
- Redux Toolkit is the official way to write Redux; createSlice and configureStore do the repetitive work.
- Reducers look like they mutate state; Immer turns the mutation into a new state.
- Dispatch the result of calling an action creator, never the creator.
- A reducer either mutates the draft or returns a new value, never both.
- Selectors own the maths, so totals stay consistent: six orders, Rs 66,350, Lahore ahead at Rs 25,100.
Where this leaves you
Redux Toolkit earns its place the first time two components disagree about the same number and the fix is not another prop. The demo showed the shape of it: a slice small enough to read in one sitting, selectors that own the maths, and a store that caught the mistake with a warning. Start with the smallest slice that holds the shared state, write the selectors beside it, and add a second only when the first has told the truth. The boilerplate Redux was famous for is mostly gone; what is left is deciding where state lives.
Further reading
- Redux Toolkit getting started
- createSlice API reference
- Why Redux Toolkit is Redux today
- Zustand: React State Without the Boilerplate
- Fastify: A Fast Node API Without the Ceremony
- React useEffect Explained: When to Use It and Skip It Waqas Shahid is a software engineer from Karachi with more than 12 years of experience, including 6+ years in engineering leadership. He writes The Practical Developer.
Top comments (0)