{"record":{"id":"afeb4224217d1b45","repo":"reduxjs/react-redux","slug":"you-must-pass-a-function-as-a-selector-to-useselec","errorCode":null,"errorMessage":"You must pass a function as a selector to useSelector","messagePattern":"You must pass a function as a selector to useSelector","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/hooks/useSelector.ts","lineNumber":153,"sourceCode":"      ? 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>(\n      {\n        [selector.name](state: TState) {\n          const selected = selector(state)","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/reduxjs/react-redux/blob/16f1a91eb2cc3817bf63753e8c90e528a9f0580c/src/hooks/useSelector.ts#L135-L171","documentation":"Besides being truthy, the first argument to useSelector must be a function. Development builds throw this when a non-function truthy value (object, string, number) is passed as the selector.","triggerScenarios":"useSelector(someObject) — e.g. passing a state slice or an options object as the first argument instead of the second, or passing an incorrectly memoized value instead of a selector function.","commonSituations":"Argument order mistakes when adopting the newer useSelector(fn, { equalityFn }) options signature, passing a reselect selector's result rather than the selector itself, or passing a class instance.","solutions":["Move options to the second argument: useSelector(mySelector, { equalityFn: shallowEqual })","Pass the selector function itself, not its output","Ensure any HOC/wrapper around the selector actually returns a function"],"exampleFix":"// before\nconst value = useSelector({ equalityFn: shallowEqual })\n// after\nconst value = useSelector(state => state.items, { equalityFn: shallowEqual })","handlingStrategy":"type-guard","validationCode":"if (process.env.NODE_ENV !== 'production' && typeof mySelector !== 'function') {\n  throw new TypeError(`useSelector expects a function, got ${typeof mySelector}`)\n}","typeGuard":"function isUseSelectorCall(fn: unknown, opts?: unknown): boolean {\n  return typeof fn === 'function' && (opts === undefined || typeof opts === 'function' || (typeof opts === 'object' && opts !== null));\n}","tryCatchPattern":null,"preventionTips":["Never pass an options object as the first argument to useSelector","Import the selector, not its computed result: useSelector(selectItems) not useSelector(selectItems(store))","Enable TypeScript overloads for useSelector so wrong argument order is a compile error"],"tags":["react-redux","hooks","useselector","type-error"],"backgroundTag":"missing-redux-provider","analyzedSha":"16f1a91eb2cc3817bf63753e8c90e528a9f0580c","analyzedAt":"2026-08-31T22:28:37.628Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}