@samitouri / QOS-React / commits / 7ab8a8e979

Added Flow type to keep hooks dispatchers in-sync (#14599)

* Added Flow type to keep hooks dispatchers in-sync

Brian Vaughn committed Jan 16, 2019 at 12:49 UTC 7ab8a8e979ff47296d381f71605187f358f96697
2 files changed +13 -7
packages/react-debug-tools/src/ReactDebugHooks.js
+2 -1
@@ -10,6 +10,7 @@
10 import type {ReactContext, ReactProviderType} from 'shared/ReactTypes';
11 import type {Fiber} from 'react-reconciler/src/ReactFiber';
12 import type {Hook} from 'react-reconciler/src/ReactFiberHooks';
13 +import typeof {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactFiberDispatcher';
14
15 import ErrorStackParser from 'error-stack-parser';
16 import ReactSharedInternals from 'shared/ReactSharedInternals';
@@ -209,7 +210,7 @@ function useMemo<T>(
210 return value;
211 }
212
212 -const Dispatcher = {
213 +const Dispatcher: DispatcherType = {
214 readContext,
215 useCallback,
216 useContext,
packages/react-dom/src/server/ReactPartialRendererHooks.js
+11 -6
@@ -7,6 +7,7 @@
7 * @flow
8 */
9
10 +import typeof {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactFiberDispatcher';
11 import type {ThreadID} from './ReactThreadIDAllocator';
12 import type {ReactContext} from 'shared/ReactTypes';
13 import areHookInputsEqual from 'shared/areHookInputsEqual';
@@ -326,18 +327,23 @@ function dispatchAction<A>(
327 }
328 }
329
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;
336 }
337
338 +function noop(): void {}
339 +
340 export let currentThreadID: ThreadID = 0;
341
342 export function setCurrentThreadID(threadID: ThreadID) {
343 currentThreadID = threadID;
344 }
345
340 -export const Dispatcher = {
346 +export const Dispatcher: DispatcherType = {
347 readContext,
348 useContext,
349 useMemo,
@@ -345,8 +351,7 @@ export const Dispatcher = {
351 useRef,
352 useState,
353 useLayoutEffect,
348 - // Callbacks are passed as they are in the server environment.
349 - useCallback: identity,
354 + useCallback,
355 // useImperativeHandle is not run in the server environment
356 useImperativeHandle: noop,
357 // Effects are not run in the server environment.