MCPcopy
hub / github.com/facebook/react / resolveDispatcher

Function resolveDispatcher

packages/react/src/ReactHooks.js:24–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22type Dispatch<A> = A => void;
23
24function resolveDispatcher() {
25 const dispatcher = ReactSharedInternals.H;
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://react.dev/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);
42}
43
44export function getCacheForType<T>(resourceType: () => T): T {
45 const dispatcher = ReactSharedInternals.A;

Callers 15

useContextFunction · 0.70
useStateFunction · 0.70
useReducerFunction · 0.70
useRefFunction · 0.70
useEffectFunction · 0.70
useInsertionEffectFunction · 0.70
useLayoutEffectFunction · 0.70
useCallbackFunction · 0.70
useMemoFunction · 0.70
useImperativeHandleFunction · 0.70
useDebugValueFunction · 0.70
useTransitionFunction · 0.70

Calls 1

errorMethod · 0.65

Tested by

no test coverage detected