How it works · state container for JavaScript apps

How Redux works

All of an app’s state lives in one place, and the only way to change it is to describe what happened.

Think of it like this. A bank ledger: nobody edits the balance. They add an entry, and the balance is worked out from the entries.

This is the core library. Most apps today use it through Redux Toolkit, which lives in its own repo.

  1. The store Holds the state, takes actions, and tells listeners when something changed. src/createStore.ts
  2. Reducers Your functions: given the old state and an action, return the new state. src/combineReducers.ts
  3. Middleware Functions an action passes through on its way to the store: logging, waiting for a server. src/applyMiddleware.ts
  4. Compose Joins several functions into one, each feeding the next. src/compose.ts

Follow one thing through: dispatch({ type: "todo/added", text: "tea" })

  1. The action goes through each middleware in turn. Any of them can log it, delay it or stop it.src/applyMiddleware.ts
  2. The store checks it is a plain object with a type.src/createStore.ts
  3. The store calls your reducer with the current state and the action.src/createStore.ts
  4. A combined reducer hands each slice of state to the reducer that owns it.src/combineReducers.ts
  5. The reducer returns a new state. The old one is never changed.
  6. Every listener is called, and the screen reads the new state.src/createStore.ts

The clever bit: The whole trick fits in one line

The heart of the store is one line: currentState = currentReducer(currentState, action). Because the new state is always computed from the old state and an action, you can record the actions and replay them, step backwards through them, or send them to another machine. Time-travel debugging falls out of that for free.

src/createStore.ts

Words you’ll meet

action
A plain object that says what happened, like { type: "todo/added" }.
reducer
A function that takes the old state and an action and returns the new state, without changing the old one.
store
The one object that holds the state.
middleware
Code that sits between dispatch and the reducer.

Good questions to ask next

Open Redux in Bento and ask them there. It reads the project in your browser, draws its parts as a map you can press, and opens the real code behind each one.

Take Redux apart yourself.

Free and open source. Nothing to install, no account.

More projects, taken apart

Written by hand from the code as it was on 2026-11-24 (commit ce8d836). Redux belongs to its authors; this page is an independent explanation. Spot a mistake? Tell us.