diff --git a/src/hooks/useSelector.js b/src/hooks/useSelector.js index 87b61f244..85e85d13e 100644 --- a/src/hooks/useSelector.js +++ b/src/hooks/useSelector.js @@ -107,8 +107,18 @@ export function createSelectorHook(context = ReactReduxContext) { ? useDefaultReduxContext : () => useContext(context) return function useSelector(selector, equalityFn = refEquality) { - if (process.env.NODE_ENV !== 'production' && !selector) { - throw new Error(`You must pass a selector to useSelector`) + 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 { store, subscription: contextSub } = useReduxContext() diff --git a/test/hooks/useSelector.spec.js b/test/hooks/useSelector.spec.js index 0af0176c7..17d7a80aa 100644 --- a/test/hooks/useSelector.spec.js +++ b/test/hooks/useSelector.spec.js @@ -451,6 +451,14 @@ describe('React', () => { it('throws if no selector is passed', () => { expect(() => useSelector()).toThrow() }) + + it('throws if selector is not a function', () => { + expect(() => useSelector(1)).toThrow() + }) + + it('throws if equality function is not a function', () => { + expect(() => useSelector((s) => s.count, 1)).toThrow() + }) }) })