{"record":{"id":"1b14d38c7db5ee1d","repo":"reduxjs/react-redux","slug":"you-must-pass-a-function-as-an-equality-function-t","errorCode":null,"errorMessage":"You must pass a function as an equality function to useSelector","messagePattern":"You must pass a function as an equality function to useSelector","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/hooks/useSelector.ts","lineNumber":156,"sourceCode":"  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)\n          if (process.env.NODE_ENV !== 'production') {\n            const { devModeChecks = {} } =\n              typeof equalityFnOrOptions === 'function'","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/reduxjs/react-redux/blob/16f1a91eb2cc3817bf63753e8c90e528a9f0580c/src/hooks/useSelector.ts#L138-L174","documentation":"When using the options form useSelector(selector, { equalityFn }), the equalityFn field must be a function (e.g. shallowEqual). Development builds throw this when it is a non-function truthy value such as a string or object.","triggerScenarios":"useSelector(fn, { equalityFn: 'shallow' }) or passing a misremembered constant/flag instead of a comparison function.","commonSituations":"Misreading docs and passing a string enum describing the comparison instead of the function import from react-redux.","solutions":["Import a real comparator: import { shallowEqual } from 'react-redux' and pass it directly","Or use the shorthand: useSelector(fn, shallowEqual)","Remove the equalityFn field if the default reference equality is acceptable"],"exampleFix":"// before\nuseSelector(sel, { equalityFn: 'shallow' })\n// after\nimport { shallowEqual } from 'react-redux'\nuseSelector(sel, { equalityFn: shallowEqual })","handlingStrategy":"type-guard","validationCode":"import { shallowEqual } from 'react-redux'\nconst eq = shallowEqual // must be a function\nif (process.env.NODE_ENV !== 'production' && typeof eq !== 'function') {\n  throw new TypeError('equalityFn must be a function, e.g. shallowEqual')\n}","typeGuard":"function isEqualityFn(v: unknown): v is (a: any, b: any) => boolean {\n  return typeof v === 'function' && v.length >= 2;\n}","tryCatchPattern":null,"preventionTips":["Always import equality comparators (shallowEqual, refEquality) rather than writing string flags","Prefer the shorthand useSelector(fn, shallowEqual) when no other options are needed","Add a unit test asserting your wrapped useSelector helper validates equalityFn"],"tags":["react-redux","hooks","useselector","equality-function","validation"],"backgroundTag":"missing-redux-provider","analyzedSha":"16f1a91eb2cc3817bf63753e8c90e528a9f0580c","analyzedAt":"2026-08-31T22:28:37.628Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}