Skip to content

Commit 7ab8a8e

Browse files
authored
Added Flow type to keep hooks dispatchers in-sync (#14599)
* Added Flow type to keep hooks dispatchers in-sync
1 parent 4392e38 commit 7ab8a8e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Diff for: packages/react-debug-tools/src/ReactDebugHooks.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import type {ReactContext, ReactProviderType} from 'shared/ReactTypes';
1111
import type {Fiber} from 'react-reconciler/src/ReactFiber';
1212
import type {Hook} from 'react-reconciler/src/ReactFiberHooks';
13+
import typeof {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactFiberDispatcher';
1314

1415
import ErrorStackParser from 'error-stack-parser';
1516
import ReactSharedInternals from 'shared/ReactSharedInternals';
@@ -209,7 +210,7 @@ function useMemo<T>(
209210
return value;
210211
}
211212

212-
const Dispatcher = {
213+
const Dispatcher: DispatcherType = {
213214
readContext,
214215
useCallback,
215216
useContext,

Diff for: packages/react-dom/src/server/ReactPartialRendererHooks.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @flow
88
*/
99

10+
import typeof {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactFiberDispatcher';
1011
import type {ThreadID} from './ReactThreadIDAllocator';
1112
import type {ReactContext} from 'shared/ReactTypes';
1213
import areHookInputsEqual from 'shared/areHookInputsEqual';
@@ -326,27 +327,31 @@ function dispatchAction<A>(
326327
}
327328
}
328329

329-
function noop(): void {}
330-
function identity(fn: Function): Function {
331-
return fn;
330+
export function useCallback<T>(
331+
callback: T,
332+
inputs: Array<mixed> | void | null,
333+
): T {
334+
// Callbacks are passed as they are in the server environment.
335+
return callback;
332336
}
333337

338+
function noop(): void {}
339+
334340
export let currentThreadID: ThreadID = 0;
335341

336342
export function setCurrentThreadID(threadID: ThreadID) {
337343
currentThreadID = threadID;
338344
}
339345

340-
export const Dispatcher = {
346+
export const Dispatcher: DispatcherType = {
341347
readContext,
342348
useContext,
343349
useMemo,
344350
useReducer,
345351
useRef,
346352
useState,
347353
useLayoutEffect,
348-
// Callbacks are passed as they are in the server environment.
349-
useCallback: identity,
354+
useCallback,
350355
// useImperativeHandle is not run in the server environment
351356
useImperativeHandle: noop,
352357
// Effects are not run in the server environment.

0 commit comments

Comments
 (0)