File tree 2 files changed +20
-2
lines changed
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) {
107
107
? useDefaultReduxContext
108
108
: ( ) => useContext ( context )
109
109
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
+ }
112
122
}
113
123
const { store, subscription : contextSub } = useReduxContext ( )
114
124
Original file line number Diff line number Diff line change @@ -451,6 +451,14 @@ describe('React', () => {
451
451
it ( 'throws if no selector is passed' , ( ) => {
452
452
expect ( ( ) => useSelector ( ) ) . toThrow ( )
453
453
} )
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
+ } )
454
462
} )
455
463
} )
456
464
You can’t perform that action at this time.
0 commit comments