What is Redux?
Redux is a predictable state container: the entire app state lives in a single store, it can only change by dispatching actions (plain objects describing what happened), and pure reducer functions compute the next state. Components read state with selectors and dispatch actions. Today Redux is written with Redux Toolkit, the official recommended approach.
Core principles
- Single source of truth: one store holds the global state tree.
- State is read-only: the only way to change it is to dispatch an action.
- Changes are made with pure functions: reducers
(state, action) => newState, no side effects.
Data flow
UI event → dispatch(action) → middleware (logging, async) → reducers → new state → subscribed components re-render with selected data.
React integration
react-redux provides <Provider store>, useSelector(selector) and useDispatch(). useSelector uses useSyncExternalStore, so it is concurrency-safe and only re-renders when the selected value changes.
Why people use it
- Predictable updates that are easy to trace and test.
- Redux DevTools: action history, state diffs, time-travel debugging.
- Middleware ecosystem.
- RTK Query for server data caching.
Criticisms (mostly of "classic" Redux)
Boilerplate (action types, action creators, switch reducers, immutable updates by hand) and overuse for simple state. Redux Toolkit removes most boilerplate, and many apps choose lighter tools (Zustand, Context, TanStack Query) when they do not need Redux's structure.
Current versions
Redux Toolkit 2.x and React Redux 9.x.
Code example
1// Classic Redux concepts (for understanding; use Redux Toolkit in real apps)2type State = { count: number };3type Action = { type: "counter/incremented" } | { type: "counter/added"; amount: number };45function counterReducer(state: State = { count: 0 }, action: Action): State {6 switch (action.type) {7 case "counter/incremented":8 return { count: state.count + 1 };9 case "counter/added":10 return { count: state.count + action.amount };11 default:12 return state;13 }14}1516// Modern equivalent with Redux Toolkit17import { configureStore, createSlice } from "@reduxjs/toolkit";1819const counter = createSlice({20 name: "counter",21 initialState: { count: 0 },22 reducers: {23 incremented: (s) => void s.count++,24 added: (s, a: { payload: number }) => void (s.count += a.payload),25 },26});2728export const store = configureStore({ reducer: { counter: counter.reducer, legacy: counterReducer } });29store.dispatch(counter.actions.added(5));30console.log(store.getState().counter.count); // 5
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.