Small tweaks to SSR to match #14594 (#14618)

* Small tweaks to SSR to match #14594

* Remove unnecessary comparison
This commit is contained in:
Dan Abramov 2019-01-18 00:52:13 +00:00 committed by GitHub
parent 17d70df919
commit be457ca685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 17 deletions

View File

@ -286,29 +286,26 @@ export function useReducer<S, A>(
}
}
function useMemo<T>(
nextCreate: () => T,
inputs: Array<mixed> | void | null,
): T {
function useMemo<T>(nextCreate: () => T, deps: Array<mixed> | void | null): T {
currentlyRenderingComponent = resolveCurrentlyRenderingComponent();
workInProgressHook = createWorkInProgressHook();
const nextInputs =
inputs !== undefined && inputs !== null ? inputs : [nextCreate];
const nextDeps = deps === undefined ? null : deps;
if (
workInProgressHook !== null &&
workInProgressHook.memoizedState !== null
) {
if (workInProgressHook !== null) {
const prevState = workInProgressHook.memoizedState;
const prevInputs = prevState[1];
if (areHookInputsEqual(nextInputs, prevInputs)) {
return prevState[0];
if (prevState !== null) {
if (nextDeps !== null) {
const prevDeps = prevState[1];
if (areHookInputsEqual(nextDeps, prevDeps)) {
return prevState[0];
}
}
}
}
const nextValue = nextCreate();
workInProgressHook.memoizedState = [nextValue, nextInputs];
workInProgressHook.memoizedState = [nextValue, nextDeps];
return nextValue;
}
@ -330,7 +327,7 @@ function useRef<T>(initialValue: T): {current: T} {
export function useLayoutEffect(
create: () => mixed,
inputs: Array<mixed> | void | null,
deps: Array<mixed> | void | null,
) {
if (__DEV__) {
currentHookNameInDev = 'useLayoutEffect';
@ -388,7 +385,7 @@ function dispatchAction<A>(
export function useCallback<T>(
callback: T,
inputs: Array<mixed> | void | null,
deps: Array<mixed> | void | null,
): T {
// Callbacks are passed as they are in the server environment.
return callback;

View File

@ -303,7 +303,7 @@ class ReactShallowRenderer {
this._validateCurrentlyRenderingComponent();
this._createWorkInProgressHook();
const nextDeps = deps !== undefined && deps !== null ? deps : null;
const nextDeps = deps !== undefined ? deps : null;
if (
this._workInProgressHook !== null &&