diff --git a/packages/react-debug-tools/src/ReactDebugHooks.js b/packages/react-debug-tools/src/ReactDebugHooks.js index 1256c8fa8330f..b53fab87d46d8 100644 --- a/packages/react-debug-tools/src/ReactDebugHooks.js +++ b/packages/react-debug-tools/src/ReactDebugHooks.js @@ -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( return value; } -const Dispatcher = { +const Dispatcher: DispatcherType = { readContext, useCallback, useContext, diff --git a/packages/react-dom/src/server/ReactPartialRendererHooks.js b/packages/react-dom/src/server/ReactPartialRendererHooks.js index 6eb62c7bd7c2d..a4cf6ce04f8d3 100644 --- a/packages/react-dom/src/server/ReactPartialRendererHooks.js +++ b/packages/react-dom/src/server/ReactPartialRendererHooks.js @@ -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( } } -function noop(): void {} -function identity(fn: Function): Function { - return fn; +export function useCallback( + callback: T, + inputs: Array | 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.