Added Flow type to keep hooks dispatchers in-sync (#14599)
* Added Flow type to keep hooks dispatchers in-sync
This commit is contained in:
parent
4392e3821d
commit
7ab8a8e979
|
@ -10,6 +10,7 @@
|
|||
import type {ReactContext, ReactProviderType} from 'shared/ReactTypes';
|
||||
import type {Fiber} from 'react-reconciler/src/ReactFiber';
|
||||
import type {Hook} from 'react-reconciler/src/ReactFiberHooks';
|
||||
import typeof {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactFiberDispatcher';
|
||||
|
||||
import ErrorStackParser from 'error-stack-parser';
|
||||
import ReactSharedInternals from 'shared/ReactSharedInternals';
|
||||
|
@ -209,7 +210,7 @@ function useMemo<T>(
|
|||
return value;
|
||||
}
|
||||
|
||||
const Dispatcher = {
|
||||
const Dispatcher: DispatcherType = {
|
||||
readContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* @flow
|
||||
*/
|
||||
|
||||
import typeof {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactFiberDispatcher';
|
||||
import type {ThreadID} from './ReactThreadIDAllocator';
|
||||
import type {ReactContext} from 'shared/ReactTypes';
|
||||
import areHookInputsEqual from 'shared/areHookInputsEqual';
|
||||
|
@ -326,18 +327,23 @@ function dispatchAction<A>(
|
|||
}
|
||||
}
|
||||
|
||||
function noop(): void {}
|
||||
function identity(fn: Function): Function {
|
||||
return fn;
|
||||
export function useCallback<T>(
|
||||
callback: T,
|
||||
inputs: Array<mixed> | void | null,
|
||||
): T {
|
||||
// Callbacks are passed as they are in the server environment.
|
||||
return callback;
|
||||
}
|
||||
|
||||
function noop(): void {}
|
||||
|
||||
export let currentThreadID: ThreadID = 0;
|
||||
|
||||
export function setCurrentThreadID(threadID: ThreadID) {
|
||||
currentThreadID = threadID;
|
||||
}
|
||||
|
||||
export const Dispatcher = {
|
||||
export const Dispatcher: DispatcherType = {
|
||||
readContext,
|
||||
useContext,
|
||||
useMemo,
|
||||
|
@ -345,8 +351,7 @@ export const Dispatcher = {
|
|||
useRef,
|
||||
useState,
|
||||
useLayoutEffect,
|
||||
// Callbacks are passed as they are in the server environment.
|
||||
useCallback: identity,
|
||||
useCallback,
|
||||
// useImperativeHandle is not run in the server environment
|
||||
useImperativeHandle: noop,
|
||||
// Effects are not run in the server environment.
|
||||
|
|
Loading…
Reference in New Issue