useSelector keeps re-rendering a component although the data did not change
A component re-renders after every dispatched action, even unrelated onesShort answer
useSelector compares the value your selector returns with the previous one using ===. If the selector builds a new object or array on every call, or the reducer swaps in new references for unchanged data, the comparison fails after every action and the component renders again. Return stable references instead.
Fix it fast
1Find out which cause you have
Log what your selector returns and compare it with the previous value using ===. A false for identical-looking data tells you the selector is creating a new reference.
const prev = useRef(); const value = useSelector(selectThing); console.log('same reference?', prev.current === value); prev.current = value;2Match what you see, then jump to its fix
- 1
The selector contains an object literal, [...], .map() or .filter() inside the function passed to useSelectorThe selector returns a new object or array on every callFix - 2
The selector ends in .filter(...) or .map(...), so its result is a fresh array each timeDerived data (filter, map, sort) is computed inside the selectorFix - 3
useSelector((state) => state), or a selector that reads one big slice but the component uses two fieldsThe selector returns the whole state, or a large sliceFix - 4
The selected value is a plain slice or item, yet it still changes identity after unrelated actionsA reducer returns new references for data that did not changeFix
- 1
What does the error look like?
A component re-renders after every dispatched action, even unrelated onesThe React Profiler lists the component in every commit, including commits caused by unrelated state
Cause 1 of 4
The selector returns a new object or array on every call
1Check
The React Redux docs state that returning a new object from a selector forces a render after every dispatched action, because the default equality check is strict reference equality. Search for selectors that build objects.
grep -rn "useSelector((state) => ({" src2Fix
Select each field with its own useSelector call, or pass shallowEqual as the equality function if the object really must be built in the selector.
import { shallowEqual, useSelector } from 'react-redux';
// option 1: one call per field
const count = useSelector((state) => state.count);
const user = useSelector((state) => state.user);
// option 2: keep the object, compare its fields
const data = useSelector(
(state) => ({ count: state.count, user: state.user }),
shallowEqual
);3Verify
Dispatch an unrelated action. The component no longer shows up in the Profiler for that commit.
store.dispatch({ type: 'unrelated/ping' });Confirmed by redux.js.org
Cause 2 of 4
Derived data (filter, map, sort) is computed inside the selector
1Check
A filtered array is a new array even when every item is the same. The Redux style guide recommends memoized selectors for exactly this case.
grep -rn "useSelector.*\.\(filter\|map\|sort\)(" src2Fix
Create the selector once, outside the component, with createSelector. It recomputes only when its input selectors return new values.
import { createSelector } from '@reduxjs/toolkit';
const selectTodos = (state) => state.todos.list;
const selectFilter = (state) => state.todos.filter;
export const selectVisibleTodos = createSelector(
[selectTodos, selectFilter],
(todos, filter) => todos.filter((t) => t.status === filter)
);
// in the component
const visible = useSelector(selectVisibleTodos);3Verify
Dispatch an action that changes another slice. The component does not render again.
console.count('TodoList render');Confirmed by redux.js.org
Cause 3 of 4
The selector returns the whole state, or a large slice
1Check
The React Redux docs describe an identity-function check in development builds: it warns when a selector returns the entire root state, because the component then re-renders on any state change.
grep -rn "useSelector((state) => state)" src2Fix
Select only the values the component displays, using narrow selectors. The Redux style guide advises many small useSelector calls over one large one.
const user = useSelector(selectCurrentUser);
const status = useSelector(selectUserStatus);3Verify
The development warning about returning the root state is gone, and renders drop to the actions that touch those values.
console.count('Profile render');Confirmed by redux.js.org
Cause 4 of 4
A reducer returns new references for data that did not change
1Check
Redux state must be updated immutably, but only the parts that change should get new references. A reducer that rebuilds the whole slice for every action breaks the === check for every reader.
// look for reducers that always spread or recreate the slice
grep -rn "return {" src/features2Fix
Use createSlice, which is built on Immer: the Redux style guide notes that Immer tracks your changes and produces immutably updated values, so the parts you did not touch keep their references.
const todosSlice = createSlice({
name: 'todos',
initialState,
reducers: {
todoToggled(state, action) {
const todo = state.byId[action.payload];
if (todo) todo.completed = !todo.completed;
},
},
});3Verify
Log the selected value before and after an unrelated action; the reference comparison is now true.
console.log(store.getState().todos === before);Confirmed by redux.js.org
How do I stop it coming back?
- Define createSelector selectors outside components so every render shares one instance.
- Write many narrow useSelector calls instead of one that builds an object.
- Keep the development checks on; they warn about unstable selectors and root-state selectors.
- Profile with the React Profiler before optimising: only fix components that render visibly often.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
useDispatch or useSelector throws: could not find react-redux context value
Could not find "store" in the context of "Connect(MyComponent)"
React Redux hooks read the store from React context.
4 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix