{"record":{"id":"48fd2823163821f8","repo":"reduxjs/react-redux","slug":"selector-selector-name-unknown-returned-th","errorCode":null,"errorMessage":"Selector ${selector.name || 'unknown'} returned the root state when called. This can lead to unnecessary rerenders.\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.","messagePattern":"Selector (.+?) returned the root state when called\\. This can lead to unnecessary rerenders\\.\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever \\*anything\\* in state changes\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/hooks/useSelector.ts","lineNumber":226,"sourceCode":"                    stack,\n                  },\n                )\n              }\n            }\n            if (\n              finalIdentityFunctionCheck === 'always' ||\n              (finalIdentityFunctionCheck === 'once' && firstRun.current)\n            ) {\n              // @ts-ignore\n              if (selected === state) {\n                let stack: string | undefined = undefined\n                try {\n                  throw new Error()\n                } catch (e) {\n                  // eslint-disable-next-line no-extra-semi\n                  ;({ stack } = e as Error)\n                }\n                console.warn(\n                  'Selector ' +\n                    (selector.name || 'unknown') +\n                    ' returned the root state when called. This can lead to unnecessary rerenders.' +\n                    '\\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.',\n                  { stack },\n                )\n              }\n            }\n            if (firstRun.current) firstRun.current = false\n          }\n          return selected\n        },\n      }[selector.name],\n      [selector],\n    )\n\n    const selectedState = useSyncExternalStoreWithSelector(\n      subscription.addNestedSub,","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/reduxjs/react-redux/blob/16f1a91eb2cc3817bf63753e8c90e528a9f0580c/src/hooks/useSelector.ts#L208-L244","documentation":"useSelector runs a dev-mode check that warns when a selector returns the entire state object (result === state). Returning the root state means the subscribed component re-renders whenever ANY part of the store changes, since the root state reference changes on every dispatched action. The library flags it because returning the whole state from a selector is almost always an accidental mistake.","triggerScenarios":"Passing an identity-ish selector such as useSelector(state => state) or useSelector(state => ({...state})) effectively; using a selector that ignores its argument and returns the store/state; accidentally passing a non-selector (e.g. the store itself or a mis-bound function) to useSelector.","commonSituations":"Copy-pasted hook code where the selector body was deleted leaving state => state; new developers grabbing \"all data\" to destructure later; TypeScript mistakes where a generic selector defaults to RootState; refactoring where the intended slice selector was replaced by the state parameter itself.","solutions":["Select the narrowest slice needed: useSelector(state => state.users) instead of useSelector(state => state).","Split data needs into multiple useSelector calls per slice/field.","If truly whole-state access is needed (rare), accept the re-render cost or subscribe via useStore + manual logic instead.","Double-check the function passed to useSelector actually selects — it must take state and return derived data, not the store or state itself.","Use typed hooks (TypedUseSelectorHook<RootState>) so mistakes like returning state are visible in review."],"exampleFix":"// before\nconst state = useSelector(state => state)\nconst user = state.user\n\n// after\nconst user = useSelector(state => state.user)\n// or for multiple slices:\nconst user = useSelector(state => state.user)\nconst items = useSelector(state => state.items)","handlingStrategy":"validation","validationCode":"// Assert a selector never returns the root state\nfunction assertNotRootState(selector, state) {\n  const result = selector(state)\n  if (result === state) {\n    throw new Error(`${selector.name || 'unknown'} returns the root state; select a narrower slice instead`)\n  }\n  return selector\n}\n// usage: const safeSelector = assertNotRootState(mySelector, store.getState())","typeGuard":null,"tryCatchPattern":"null","preventionTips":["Select the smallest slice each component needs; one useSelector per slice.","Never write useSelector(state => state); destructure at store level only in tests/debug tools.","Use typed hooks (TypedUseSelectorHook<RootState>) to keep selector return types explicit and reviewable.","In CI, assert no console.warn about root-state selectors during component tests.","If whole-state reactivity is intentional, document it and bypass useSelector (useStore + subscription) to make the choice explicit."],"tags":["react-redux","redux","useselector","performance","rerender","state"],"backgroundTag":"selector-returns-root-state","analyzedSha":"16f1a91eb2cc3817bf63753e8c90e528a9f0580c","analyzedAt":"2026-08-31T22:28:37.628Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}