reduxjs/react-redux · error
You must pass a function as an equality function to useSelec
Error message
You must pass a function as an equality function to useSelector
What it means
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.
Source
Thrown at src/hooks/useSelector.ts:156
const useSelector = <TState, Selected>(
selector: (state: TState) => Selected,
equalityFnOrOptions:
| EqualityFn<NoInfer<Selected>>
| UseSelectorOptions<NoInfer<Selected>> = {},
): Selected => {
const { equalityFn = refEquality } =
typeof equalityFnOrOptions === 'function'
? { equalityFn: equalityFnOrOptions }
: equalityFnOrOptions
if (process.env.NODE_ENV !== 'production') {
if (!selector) {
throw new Error(`You must pass a selector to useSelector`)
}
if (typeof selector !== 'function') {
throw new Error(`You must pass a function as a selector to useSelector`)
}
if (typeof equalityFn !== 'function') {
throw new Error(
`You must pass a function as an equality function to useSelector`,
)
}
}
const reduxContext = useReduxContext()
const { store, subscription, getServerState } = reduxContext
const firstRun = React.useRef(true)
const wrappedSelector = React.useCallback<typeof selector>(
{
[selector.name](state: TState) {
const selected = selector(state)
if (process.env.NODE_ENV !== 'production') {
const { devModeChecks = {} } =
typeof equalityFnOrOptions === 'function'View on GitHub (pinned to 16f1a91eb2)
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
Example fix
// before
useSelector(sel, { equalityFn: 'shallow' })
// after
import { shallowEqual } from 'react-redux'
useSelector(sel, { equalityFn: shallowEqual }) Defensive patterns
Strategy: type-guard
Validate before calling
import { shallowEqual } from 'react-redux'
const eq = shallowEqual // must be a function
if (process.env.NODE_ENV !== 'production' && typeof eq !== 'function') {
throw new TypeError('equalityFn must be a function, e.g. shallowEqual')
} Type guard
function isEqualityFn(v: unknown): v is (a: any, b: any) => boolean {
return typeof v === 'function' && v.length >= 2;
} Prevention
- 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
When it happens
Trigger: useSelector(fn, { equalityFn: 'shallow' }) or passing a misremembered constant/flag instead of a comparison function.
Common situations: Misreading docs and passing a string enum describing the comparison instead of the function import from react-redux.
Related errors
- You must pass a selector to useSelector
- You must pass a function as a selector to useSelector
- could not find react-redux context value; please ensure the
- You must pass a component to the function returned by connec
- You must pass a valid React context consumer as `props.conte
AI-assisted analysis of reduxjs/react-redux@16f1a91eb2 (2026-08-31).
Data as JSON: /api/errors/1b14d38c7db5ee1d.
Report an issue: GitHub.