Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -209,7 +210,7 @@ function useMemo<T>(
return value;
}

const Dispatcher = {
const Dispatcher: DispatcherType = {
readContext,
useCallback,
useContext,
Expand Down
17 changes: 11 additions & 6 deletions packages/react-dom/src/server/ReactPartialRendererHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -326,27 +327,31 @@ 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,
useReducer,
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.
Expand Down