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