77 * @flow
88 */
99
10+ import type { Dispatcher } from 'react-reconciler/src/ReactInternalTypes' ;
1011import type {
1112 MutableSource ,
1213 MutableSourceGetSnapshotFn ,
@@ -15,25 +16,29 @@ import type {
1516} from 'shared/ReactTypes' ;
1617import type { OpaqueIDType } from 'react-reconciler/src/ReactFiberHostConfig' ;
1718
18- import invariant from 'shared/invariant' ;
19-
2019import ReactCurrentDispatcher from './ReactCurrentDispatcher' ;
2120
2221type BasicStateAction < S > = ( S => S ) | S ;
2322type Dispatch < A > = A => void ;
2423
2524function resolveDispatcher ( ) {
2625 const dispatcher = ReactCurrentDispatcher . current ;
27- invariant (
28- dispatcher !== null ,
29- 'Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for' +
30- ' one of the following reasons:\n' +
31- '1. You might have mismatching versions of React and the renderer (such as React DOM)\n' +
32- '2. You might be breaking the Rules of Hooks\n' +
33- '3. You might have more than one copy of React in the same app\n' +
34- 'See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.' ,
35- ) ;
36- return dispatcher ;
26+ if ( __DEV__ ) {
27+ if ( dispatcher === null ) {
28+ console . error (
29+ 'Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for' +
30+ ' one of the following reasons:\n' +
31+ '1. You might have mismatching versions of React and the renderer (such as React DOM)\n' +
32+ '2. You might be breaking the Rules of Hooks\n' +
33+ '3. You might have more than one copy of React in the same app\n' +
34+ 'See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.' ,
35+ ) ;
36+ }
37+ }
38+ // Will result in a null access error if accessed outside render phase. We
39+ // intentionally don't throw our own error because this is in a hot path.
40+ // Also helps ensure this is inlined.
41+ return ( ( dispatcher : any ) : Dispatcher ) ;
3742}
3843
3944export function getCacheForType < T > ( resourceType : ( ) = > T ) : T {
0 commit comments