Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 41 ยท Patterns and Performance

Re-renders and Performance in Redux

Learn how React-Redux decides when to re-render, how useSelector equality works, how to avoid unnecessary renders with narrow selectors, and how to keep Redux apps fast.

Redux itself is fast: a dispatch runs your reducers and notifies subscribers. Slowness in Redux apps almost always comes from too many components re-rendering, or from expensive work done on every update. To fix it, you need to know exactly how React-Redux decides when a component should render.

How useSelector decides

When the store changes, React-Redux calls the selector of every useSelector on the page with the new state and compares the new return value with the previous one using === (strict reference equality). If they are different, the component re-renders. If they are equal, it does not.

flowchart TD
  A["dispatch(action)"] --> B["reducers produce new state"]
  B --> C["store notifies subscribers"]
  C --> D["each useSelector runs its selector"]
  D --> E{"result === previous?"}
  E -- "yes" --> F["no re-render"]
  E -- "no" --> G["re-render component"]

The selector, not the dispatched action, decides who re-renders.

So the performance rule is: make selectors return stable values for unchanged data. A primitive (state.user.name) is stable by nature. An object or array built inside the selector is a new reference every time.

Observing it

Here is a stand-in "useSelector" that tracks results, so you can see which subscribers would re-render after each dispatch. (React-Redux is not available in the editors; the logic is the same strict equality check.)

JS Which selectors trigger a render?

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

No output.

Three unrelated dispatches caused three renders for the selector that builds a new array and for the one that selects the whole state, and zero renders for the others. Passing shallowEqual (or using a memoized selector) cures the new-array case.

Techniques that work

1. Select the smallest value. useSelector(selectUserName) beats useSelector(selectUser) if you only show the name. Never select the entire state.

2. Select primitives, derive in the component. Two useSelector calls returning strings are cheaper to reason about than one that returns { a, b }.

3. Memoize derived arrays and objects with createSelector (see selectors), or pass an equality function:

JSX
// Real React-Redux code (read-only)
import { shallowEqual, useSelector } from 'react-redux';

const { name, role } = useSelector(
  (state) => ({ name: state.user.name, role: state.user.role }),
  shallowEqual,
);

4. Pass ids to list rows, not whole objects. The list re-renders only when the ids change, and each row subscribes to its own entity (see createEntityAdapter).

5. Wrap row components in React.memo when the parent re-renders often. With React 19's compiler this is often automatic, but a memoized row that only receives an id prop is cheap insurance.

6. Do work in reducers or selectors, not in the render body. Sorting 10,000 items inside a component runs on every render. Put it in a memoized selector.

7. Keep actions small and rare. Dispatching on every mousemove or keystroke into the store re-runs every selector each time. Keep fast-changing values (drag position, text being typed) in component state and dispatch the final value.

Batching and dispatching many actions

Dispatching three actions in a row means three runs of all selectors. React 18+ batches the React renders automatically, so you get one commit, but reducers and selectors still run three times. Prefer one action that carries the whole change (checkoutCompleted) handled by several slices over a sequence of small ones, and bulk actions (todosAdded(list)) over looping dispatch.

Measuring before optimizing

Do not guess. Use:

  • React DevTools Profiler (record, then "Why did this render?").
  • Redux DevTools to see how often actions fire and how long they take.
  • A dev-only warning that Redux Toolkit already gives you: selectors that return different results for the same input produce a console warning in development (useSelector stability check), and createSelector warns about identity result functions.
  • The immutability and serializability checks in development can slow large states; if the console prints "ImmutableStateInvariantMiddleware took 78ms," trim the state or configure immutableCheck: { warnAfter: 128 }. They are removed in production builds, so do not measure with them on.
JavaScript
// Real Redux Toolkit code (read-only)
configureStore({
  reducer,
  middleware: (gdm) => gdm({ immutableCheck: { warnAfter: 128 }, serializableCheck: { warnAfter: 128 } }),
});

A small checklist

  1. Does the selector build a new object or array? Memoize it or use shallowEqual.
  2. Is the component selecting more than it shows? Narrow it.
  3. Does a list pass full items down? Pass ids instead.
  4. Is a high-frequency value in the store? Move it to local state.
  5. Is expensive work in render? Move it to a selector.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How does React-Redux decide whether to re-render after a dispatch?

    Each selector result is compared with strict equality.
  2. 2. Which selector causes a re-render on every store update?

    map returns a new array each time, so === is always false.
  3. 3. What is a good way to pass list data to row components?

    Rows then re-render only when their own entity changes.
  4. 4. Where should a rapidly changing value like a drag position live?

    High-frequency updates would re-run every selector.

Summary

  • useSelector re-renders a component when its selector result changes by ===.
  • Select small, stable values; memoize or use shallowEqual for derived objects.
  • Pass ids to rows, keep fast-changing values local, and put heavy computation in memoized selectors.
  • Prefer one action describing a change over many small ones.
  • Measure with the React and Redux DevTools; development checks do not run in production.

Next: Undo/redo and persistence