Writing
React With Redux: When It Still Helps and How to Write It Now
Redux still earns its place for shared client state that many parts of an app touch. Write it with Redux Toolkit and the React-Redux hooks, and keep API data and local state out of it.
By Ka Lun Chan · Web development / Architecture
Is Redux still worth using with React?
Yes, for client state that many distant parts of an app read and update, especially when you want to trace every change. Write it with Redux Toolkit and the React-Redux hooks, and keep API data, local UI state and small shared state out of it.
I first wrote this on my old blog, under a title that called React with Redux awesome. This version keeps the reasons I liked it and updates how Redux is written now, which has changed more than the ideas have.
The short version:
- Redux is still a predictable state container, and Redux DevTools is still one of the best tools for seeing how state changed and why.
- Hand-written
createStore, action type constants and switch statements are out. Redux Toolkit’sconfigureStoreandcreateSliceare the official way in. - Many apps that reached for Redux to hold fetched data are better served by a server-state library.
| Kind of state | Where it should live | Tool |
|---|---|---|
| A single component’s UI state (an open menu, a form input) | In the component | useState |
| State a small subtree shares | In the closest common parent, passed down or via context | useReducer plus context |
| Data fetched from an API | In a server-state cache that knows about loading, staleness and refetching | TanStack Query or RTK Query |
| Client state many distant parts of the app read and update | In a global store | Redux Toolkit, or a lighter store such as Zustand |
| Where the user is in the app | In the URL | Your router |
What problem does Redux solve in a React app?
It gets shared state out of the component tree. Without it, data flows down through props and changes flow back up through callbacks, and that plumbing gets painful once many layers of components sit between the state and the code that uses it.
React’s one-way data flow is a good default. A parent passes data to its children as props, and a child can’t send data back up except by calling a function the parent handed it. With two or three layers that’s fine. With ten, every component in the middle passes along props it never uses, which is what people now call prop drilling, and every change to the shape of that data touches all of them.
Redux moves the shared state into a store outside the tree. Any component can read the slice of data it needs and dispatch an action to change it, without its parents knowing. That was the main reason I liked it, and it still holds.
How do actions, reducers and the store fit together?
An action describes what happened, a reducer decides how the state changes in response, and the store holds the state, runs the reducers when an action is dispatched and notifies the components that read from it.
- Actions are plain objects such as
{ type: 'cart/itemAdded', payload: product }. They are the only way to ask the store for a change. - Reducers are functions that take the current state and an action and return the next state, without side effects.
- The store holds the state tree, accepts dispatched actions, runs the reducers and lets subscribers know something changed.
Because every change goes through a dispatched action and a pure function, you can log each one, replay them and step back through them. That’s what makes Redux DevTools so useful when a bug depends on the order things happened in.
In the original post I described this as MVC, with React as the view and Redux as the controller. I’d qualify that now. The store is closer to the model, since it holds the state, and the reducers are the rules for changing it. Redux’s own prior art page describes reducers as the layer where model update logic lives, and traces Redux to Flux and the Elm architecture rather than MVC. The analogy helps someone coming from server-side MVC see that the view no longer owns the data, but it breaks down if you look for a controller.
What has changed in Redux since then?
Redux Toolkit became the official recommended way to write Redux, createStore was marked deprecated, the hooks API replaced connect as the default, and RTK Query arrived for data fetching. The core ideas didn’t change.
- The Redux docs call Redux Toolkit the official recommended approach for writing Redux logic.
createSlicegenerates action creators and reducers together and uses Immer, so update logic can look like a mutation while the state stays immutable. createStoreis marked deprecated in favor ofconfigureStore. The docs are clear that it’s a visual marker only: it still works and won’t be removed, andlegacy_createStoreis the same function without the strikethrough.- React-Redux recommends
useSelectoranduseDispatchas the default.connectstill works and is listed as legacy. - RTK Query is a data fetching and caching layer included in the Redux Toolkit package, so you no longer hand-write loading flags and cache logic in reducers.
- The DevTools extension I linked originally now lives in reduxjs/redux-devtools. The old repository’s README says it’s no longer the extension’s home.
What does modern Redux code look like?
A slice defines the state and its reducers, configureStore combines the slices, Provider makes the store available, and components use useSelector to read and useDispatch to send actions.
Here is a small cart in plain JavaScript, following the pattern in the Redux Toolkit quick start:
// features/cart/cartSlice.js
import { createSlice } from '@reduxjs/toolkit';
const cartSlice = createSlice({
name: 'cart',
initialState: { items: [] },
reducers: {
itemAdded(state, action) {
// Immer lets this look like a mutation; Redux still gets a new state object
state.items.push(action.payload);
},
itemRemoved(state, action) {
state.items = state.items.filter((item) => item.id !== action.payload);
},
},
});
export const { itemAdded, itemRemoved } = cartSlice.actions;
export default cartSlice.reducer;// app/store.js
import { configureStore } from '@reduxjs/toolkit';
import cartReducer from '../features/cart/cartSlice';
// configureStore also sets up the Redux DevTools extension
export const store = configureStore({
reducer: { cart: cartReducer },
});
// main.jsx
import { createRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import { store } from './app/store';
import App from './App';
createRoot(document.getElementById('root')).render(
<Provider store={store}>
<App />
</Provider>
);// features/cart/CartBadge.jsx
import { useSelector, useDispatch } from 'react-redux';
import { itemAdded } from './cartSlice';
export function CartBadge({ product }) {
const count = useSelector((state) => state.cart.items.length);
const dispatch = useDispatch();
return (
<button onClick={() => dispatch(itemAdded(product))}>
Add to cart ({count})
</button>
);
}CartBadge can sit in a header five layers away from the product list and still read and update the cart, with nothing passed through the components in between. In TypeScript, the quick start adds typed versions of the two hooks with useSelector.withTypes and useDispatch.withTypes.
When should you use Redux, and when is something else better?
Use Redux when a medium or large app has a lot of client state used in many places, updated often, with logic complex enough that you want to trace changes. For less than that, React’s own tools or a smaller library will do the job with less code.
The Redux FAQ is refreshingly honest about this. It says not every app needs Redux, that it adds concepts, code and indirection, and that it pays off with large amounts of state needed in many places, frequent updates, complex update logic, a codebase many people work on, and a need to see how state changes over time.
The alternatives I’d check first:
- Context plus
useReducer. React’s docs show how to combine a reducer with context so deep components read state and dispatch actions without prop drilling. For a small app or one feature, that’s often enough. - A server-state library. In many apps, most of what ends up in Redux is data from an API. TanStack Query treats that server state as its own problem, with caching, staleness and refetching, and RTK Query does the same inside Redux.
- A lighter store. Zustand gives you a global store as a hook with no provider, for teams that want shared state without Redux’s structure.
Once fetched data moves to a query cache and local state stays local, what’s left for a global store is often small. If it’s still large and tangled, Redux Toolkit is a good fit, and the structure that felt heavy in a small app starts paying for itself. That’s the same tradeoff I make with architecture generally: as I wrote in the architecture you don’t build, the cheapest layer is the one you didn’t need. For how React fits into a server-rendered app, see the current options for React with a Rails backend.
Sources
Checked in November against the Redux and Redux Toolkit documentation, the React-Redux hooks reference, react.dev, the TanStack Query and Zustand docs, and the Redux DevTools repositories. The table and the recommendations are mine.
- Redux Docs: Getting Started with Redux
- Redux FAQ: General (When should I use Redux?)
- Redux API: createStore (deprecation notice)
- Redux Toolkit: Quick Start
- Redux Toolkit: RTK Query Overview
- React-Redux: Hooks API
- Redux Docs: Prior Art
- react.dev: Scaling Up with Reducer and Context
- TanStack Query: Overview
- Zustand on GitHub
- Redux DevTools on GitHub (reduxjs/redux-devtools)
- Former Redux DevTools Extension repository (zalmoxisus)
Short answers
Is Redux still worth using with React?
Yes, for client state that many distant parts of an app read and update, especially when you want to trace every change with Redux DevTools. Write it with Redux Toolkit and the React-Redux hooks, and keep API data, local UI state and small shared state out of it.
Is createStore deprecated in Redux?
It is marked deprecated in favor of Redux Toolkit’s configureStore, but only as a visual marker. The Redux docs say createStore still works and will not be removed, and legacy_createStore is the same function without the deprecation tag.
Should I use connect or hooks with React-Redux?
Use the hooks, useSelector to read state and useDispatch to send actions. React-Redux recommends them as the default. connect still works and is supported, but the docs list it as legacy.
What can I use instead of Redux?
For a small app or one feature, React context combined with useReducer avoids prop drilling. For data fetched from an API, a server-state library such as TanStack Query or RTK Query handles caching and refetching. For a lighter global store, Zustand needs no provider.
Sort the state first
Before adding or removing Redux, list the state your app holds and put each piece in a row of the table above. The tool usually follows from that list, and the global store is often smaller than you expected.