File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -107,8 +107,18 @@ export function createSelectorHook(context = ReactReduxContext) {
107107 ? useDefaultReduxContext
108108 : ( ) => useContext ( context )
109109 return function useSelector ( selector , equalityFn = refEquality ) {
110- if ( process . env . NODE_ENV !== 'production' && ! selector ) {
111- throw new Error ( `You must pass a selector to useSelector` )
110+ if ( process . env . NODE_ENV !== 'production' ) {
111+ if ( ! selector ) {
112+ throw new Error ( `You must pass a selector to useSelector` )
113+ }
114+ if ( typeof selector !== 'function' ) {
115+ throw new Error ( `You must pass a function as a selector to useSelector` )
116+ }
117+ if ( typeof equalityFn !== 'function' ) {
118+ throw new Error (
119+ `You must pass a function as an equality function to useSelector`
120+ )
121+ }
112122 }
113123 const { store, subscription : contextSub } = useReduxContext ( )
114124
Original file line number Diff line number Diff line change @@ -451,6 +451,14 @@ describe('React', () => {
451451 it ( 'throws if no selector is passed' , ( ) => {
452452 expect ( ( ) => useSelector ( ) ) . toThrow ( )
453453 } )
454+
455+ it ( 'throws if selector is not a function' , ( ) => {
456+ expect ( ( ) => useSelector ( 1 ) ) . toThrow ( )
457+ } )
458+
459+ it ( 'throws if equality function is not a function' , ( ) => {
460+ expect ( ( ) => useSelector ( ( s ) => s . count , 1 ) ) . toThrow ( )
461+ } )
454462 } )
455463 } )
456464
You can’t perform that action at this time.
0 commit comments