Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 41 ยท Getting Started

Redux DevTools and Time Travel

Use the Redux DevTools extension to inspect every action, see state diffs, skip actions and jump through history. Learn why pure reducers make time travel possible, with live demos.

One of the biggest reasons to choose Redux is how easy it is to see what your app is doing. Every state change is an action, so a tool can record the list of actions and the state after each one. The Redux DevTools browser extension does exactly that. You can read the log, compare states, and even travel backwards and forwards through the history while the UI follows.

In this lesson you will learn what the DevTools show, how they are connected to a store, and why time travel works at all. The second half builds a small time-travelling store by hand so that the idea stops being magic.

The extension itself cannot run inside our editor, so the screenshots-in-words below describe it, and the live examples are stand-ins that reproduce its main features (action list, diff, skip, jump) in the console.

Installing and opening the DevTools

Install Redux DevTools for Chrome, Edge or Firefox from the browser's extension store. Then open your app, open the browser developer tools (F12) and choose the Redux tab. If you use configureStore from Redux Toolkit, no code is needed: the connection is already set up in development.

The main panels are:

  • Action list (left): every dispatched action in order, with its type. Click one to inspect it.
  • Action tab: the exact action object, including its payload.
  • State tab: the complete store state after that action.
  • Diff tab: only what changed. This is the quickest way to spot a reducer that changed too much or too little.
  • Trace tab: the call stack that dispatched the action (when tracing is enabled).
  • Test tab: generates a test skeleton from the recorded actions.
  • Slider and play controls: step through the history, or replay it as an animation.
  • Jump and Skip on each action: set the app to the state after that action, or remove the action from history.

Connecting a store

With Redux Toolkit, configureStore has a devTools option. It defaults to on in development and off in production builds.

JavaScript
// needs @reduxjs/toolkit (read-only here)
import { configureStore } from '@reduxjs/toolkit';

const store = configureStore({
  reducer: rootReducer,
  devTools: {
    name: 'Shop app',           // label in the DevTools instance list
    maxAge: 100,                // keep the last 100 actions (default 50)
    trace: true,                // record where each dispatch came from
    actionSanitizer: (action) =>
      action.type === 'auth/loggedIn' ? { ...action, payload: '***' } : action,
    stateSanitizer: (state) => ({ ...state, auth: '***' }),
  },
});

The two sanitizer options hide secrets such as tokens. They matter most when you export a recorded session or share your screen, because the full state and every payload are visible in the panel. Set devTools: false to disable the connection completely.

With the plain createStore from older code, you connect the extension with the window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ enhancer. You rarely need that now, so it is not covered further here.

Why time travel works

Time travel is not special support inside Redux. It follows from two rules you already know:

  1. Reducers are pure: same state and same action always produce the same next state.
  2. State is plain data and is never mutated, so old states are still intact.

Given those, the DevTools can rebuild any moment: start from the initial state and apply the first N actions. Skipping action 3 means applying the list without it. If a reducer reads Date.now(), uses Math.random() or calls an API, replaying gives different results and time travel breaks. That is the practical reason for the "no side effects in reducers" rule.

A time-travelling store

The example below is a stand-in for the DevTools enhancer. It records every action, and jumpTo(n) and skip(i) recompute the state by replaying actions from the initial state.

JS Jump and skip by replaying actions

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice that the store never saved the intermediate states, only the action list. Real DevTools do cache states for speed, but the idea is the same.

Breaking it on purpose

Now an impure reducer. See what time travel does to it:

JS Why impure reducers break replay

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The fix is a pattern you will use often: generate ids, timestamps and random values before dispatching (in the component, an action creator's prepare callback, or a thunk) and pass them in the payload. Redux Toolkit's prepare callbacks exist for exactly this.

Practical DevTools tips

  • Name your action types as events (cart/itemAdded). A readable action list is a readable story of the session.
  • Use the Diff tab when a reducer changes more than it should.
  • Export and import the recorded session to attach it to a bug report; another developer can replay it.
  • Persist state across reloads in the extension to avoid replaying the same steps while you tweak code.
  • Do not put huge or non-serializable values (files, class instances, promises) in actions or state. They make the DevTools slow and break replay.
  • Keep maxAge reasonable for apps that dispatch hundreds of actions per second, such as mouse tracking.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why can the DevTools jump to any earlier state?

    With pure reducers and immutable state, applying the first N actions to the initial state always produces the same result.
  2. 2. Which setting of configureStore controls the DevTools connection?

    The devTools option takes true, false or a configuration object. It is on in development and off in production by default.
  3. 3. What is a good way to give a new todo an id when you want replay to work?

    The reducer must be deterministic. Impure values are created outside and travel inside the action.
  4. 4. What does the Diff tab show?

    The Diff tab compares the state before and after the selected action, so accidental changes stand out.

Summary

  • The Redux DevTools extension records actions and states and lets you inspect, jump, skip, replay and export them.
  • configureStore connects the DevTools automatically in development; use the devTools option to name, limit or sanitize.
  • Time travel works because reducers are pure and state is immutable.
  • Impure reducers (random values, dates, global counters) break replay: create such values before dispatching.
  • Readable, event-style action names make the log useful.

Next: State and Immutability