{"record":{"id":"ce9ff015e1ca7c2f","repo":"reduxjs/react-redux","slug":"you-must-pass-a-selector-to-useselector","errorCode":null,"errorMessage":"You must pass a selector to useSelector","messagePattern":"You must pass a selector to useSelector","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/hooks/useSelector.ts","lineNumber":150,"sourceCode":"): UseSelector {\n  const useReduxContext =\n    context === ReactReduxContext\n      ? useDefaultReduxContext\n      : createReduxContextHook(context)\n\n  const useSelector = <TState, Selected>(\n    selector: (state: TState) => Selected,\n    equalityFnOrOptions:\n      | EqualityFn<NoInfer<Selected>>\n      | UseSelectorOptions<NoInfer<Selected>> = {},\n  ): Selected => {\n    const { equalityFn = refEquality } =\n      typeof equalityFnOrOptions === 'function'\n        ? { equalityFn: equalityFnOrOptions }\n        : equalityFnOrOptions\n    if (process.env.NODE_ENV !== 'production') {\n      if (!selector) {\n        throw new Error(`You must pass a selector to useSelector`)\n      }\n      if (typeof selector !== 'function') {\n        throw new Error(`You must pass a function as a selector to useSelector`)\n      }\n      if (typeof equalityFn !== 'function') {\n        throw new Error(\n          `You must pass a function as an equality function to useSelector`,\n        )\n      }\n    }\n\n    const reduxContext = useReduxContext()\n\n    const { store, subscription, getServerState } = reduxContext\n\n    const firstRun = React.useRef(true)\n\n    const wrappedSelector = React.useCallback<typeof selector>(","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/reduxjs/react-redux/blob/16f1a91eb2cc3817bf63753e8c90e528a9f0580c/src/hooks/useSelector.ts#L132-L168","documentation":"useSelector requires a selector function to read state from the store. In development builds react-redux validates arguments and throws this when the first argument is falsy (undefined, null, false).","triggerScenarios":"useSelector() or useSelector(undefined), typically because the selector import resolved to undefined (wrong named export), a dynamic import wasn't awaited, or an argument was accidentally shifted (e.g. useSelector(options) instead of useSelector(fn, options)).","commonSituations":"Renaming/renaming-away a selector export while components still import it, default-import vs named-import confusion, copy-pasted hook call where selector was deleted.","solutions":["Pass a function as the first argument: useSelector(state => state.counter.value)","Check the selector import resolves to a real export; log it if unsure","If using options form, put the function first: useSelector(mySelector, { equalityFn })"],"exampleFix":"// before\nconst value = useSelector(undefined)\n// after\nconst value = useSelector((state: RootState) => state.counter.value)","handlingStrategy":"type-guard","validationCode":"const selectValue = (state: RootState) => state.counter.value\nif (process.env.NODE_ENV !== 'production' && typeof selectValue !== 'function') {\n  throw new TypeError('useSelector requires a selector function')\n}","typeGuard":"function isSelectorFn(v: unknown): v is (state: any) => unknown {\n  return typeof v === 'function';\n}\n// usage\nif (!isSelectorFn(mySelector)) throw new TypeError('selector must be a function')\nconst value = useSelector(mySelector)","tryCatchPattern":"try {\n  const value = useSelector(selector)\n} catch (e) {\n  if (e.message.includes('pass a selector')) {\n    console.error('Selector import likely resolved to undefined')\n  }\n  throw e\n}","preventionTips":["Type selectors as (state: RootState) => T with TypeScript","Avoid default-importing selectors; use named imports so undefined exports fail the build","Keep selector and equalityFn argument order: fn first, options second"],"tags":["react-redux","hooks","useselector","validation"],"backgroundTag":"missing-redux-provider","analyzedSha":"16f1a91eb2cc3817bf63753e8c90e528a9f0580c","analyzedAt":"2026-08-31T22:28:37.628Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}