* Small tweaks to SSR to match #14594 * Remove unnecessary comparison
This commit is contained in:
parent
17d70df919
commit
be457ca685
|
@ -286,29 +286,26 @@ export function useReducer<S, A>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function useMemo<T>(
|
function useMemo<T>(nextCreate: () => T, deps: Array<mixed> | void | null): T {
|
||||||
nextCreate: () => T,
|
|
||||||
inputs: Array<mixed> | void | null,
|
|
||||||
): T {
|
|
||||||
currentlyRenderingComponent = resolveCurrentlyRenderingComponent();
|
currentlyRenderingComponent = resolveCurrentlyRenderingComponent();
|
||||||
workInProgressHook = createWorkInProgressHook();
|
workInProgressHook = createWorkInProgressHook();
|
||||||
|
|
||||||
const nextInputs =
|
const nextDeps = deps === undefined ? null : deps;
|
||||||
inputs !== undefined && inputs !== null ? inputs : [nextCreate];
|
|
||||||
|
|
||||||
if (
|
if (workInProgressHook !== null) {
|
||||||
workInProgressHook !== null &&
|
|
||||||
workInProgressHook.memoizedState !== null
|
|
||||||
) {
|
|
||||||
const prevState = workInProgressHook.memoizedState;
|
const prevState = workInProgressHook.memoizedState;
|
||||||
const prevInputs = prevState[1];
|
if (prevState !== null) {
|
||||||
if (areHookInputsEqual(nextInputs, prevInputs)) {
|
if (nextDeps !== null) {
|
||||||
return prevState[0];
|
const prevDeps = prevState[1];
|
||||||
|
if (areHookInputsEqual(nextDeps, prevDeps)) {
|
||||||
|
return prevState[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextValue = nextCreate();
|
const nextValue = nextCreate();
|
||||||
workInProgressHook.memoizedState = [nextValue, nextInputs];
|
workInProgressHook.memoizedState = [nextValue, nextDeps];
|
||||||
return nextValue;
|
return nextValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,7 +327,7 @@ function useRef<T>(initialValue: T): {current: T} {
|
||||||
|
|
||||||
export function useLayoutEffect(
|
export function useLayoutEffect(
|
||||||
create: () => mixed,
|
create: () => mixed,
|
||||||
inputs: Array<mixed> | void | null,
|
deps: Array<mixed> | void | null,
|
||||||
) {
|
) {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
currentHookNameInDev = 'useLayoutEffect';
|
currentHookNameInDev = 'useLayoutEffect';
|
||||||
|
@ -388,7 +385,7 @@ function dispatchAction<A>(
|
||||||
|
|
||||||
export function useCallback<T>(
|
export function useCallback<T>(
|
||||||
callback: T,
|
callback: T,
|
||||||
inputs: Array<mixed> | void | null,
|
deps: Array<mixed> | void | null,
|
||||||
): T {
|
): T {
|
||||||
// Callbacks are passed as they are in the server environment.
|
// Callbacks are passed as they are in the server environment.
|
||||||
return callback;
|
return callback;
|
||||||
|
|
|
@ -303,7 +303,7 @@ class ReactShallowRenderer {
|
||||||
this._validateCurrentlyRenderingComponent();
|
this._validateCurrentlyRenderingComponent();
|
||||||
this._createWorkInProgressHook();
|
this._createWorkInProgressHook();
|
||||||
|
|
||||||
const nextDeps = deps !== undefined && deps !== null ? deps : null;
|
const nextDeps = deps !== undefined ? deps : null;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this._workInProgressHook !== null &&
|
this._workInProgressHook !== null &&
|
||||||
|
|
Loading…
Reference in New Issue