diff --git a/packages/react-reconciler/src/ReactFiberHooks.js b/packages/react-reconciler/src/ReactFiberHooks.js index 82c0ec4d2a90c..2dbe17483079c 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.js +++ b/packages/react-reconciler/src/ReactFiberHooks.js @@ -174,7 +174,7 @@ type Dispatch = A => void; let renderExpirationTime: ExpirationTime = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from // the work-in-progress hook. -let currentlyRenderingFiber: Fiber | null = null; +let currentlyRenderingFiber: Fiber = (null: any); // Hooks are stored as a linked list on the fiber's memoizedState field. The // current hook list is the list that belongs to the current fiber. The @@ -259,7 +259,7 @@ function checkDepsAreArrayDev(deps: mixed) { function warnOnHookMismatchInDev(currentHookName: HookType) { if (__DEV__) { const componentName = getComponentName( - ((currentlyRenderingFiber: any): Fiber).type, + currentlyRenderingFiber.type, ); if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) { didWarnAboutMismatchedHooksForComponent.add(componentName); @@ -483,7 +483,7 @@ export function renderWithHooks( currentHook !== null && currentHook.next !== null; renderExpirationTime = NoWork; - currentlyRenderingFiber = null; + currentlyRenderingFiber = (null: any); currentHook = null; workInProgressHook = null; @@ -529,7 +529,7 @@ export function resetHooks(): void { // component is a module-style component. renderExpirationTime = NoWork; - currentlyRenderingFiber = null; + currentlyRenderingFiber = (null: any); currentHook = null; workInProgressHook = null; @@ -558,8 +558,7 @@ function mountWorkInProgressHook(): Hook { if (workInProgressHook === null) { // This is the first hook in the list - let fiber = ((currentlyRenderingFiber: any): Fiber); - fiber.memoizedState = workInProgressHook = hook; + currentlyRenderingFiber.memoizedState = workInProgressHook = hook; } else { // Append to the end of the list workInProgressHook = workInProgressHook.next = hook; @@ -575,8 +574,7 @@ function updateWorkInProgressHook(): Hook { // the dispatcher used for mounts. let nextCurrentHook: null | Hook; if (currentHook === null) { - let fiber = ((currentlyRenderingFiber: any): Fiber); - let current = fiber.alternate; + let current = currentlyRenderingFiber.alternate; if (current !== null) { nextCurrentHook = current.memoizedState; } else { @@ -588,8 +586,7 @@ function updateWorkInProgressHook(): Hook { let nextWorkInProgressHook: null | Hook; if (workInProgressHook === null) { - let fiber = ((currentlyRenderingFiber: any): Fiber); - nextWorkInProgressHook = fiber.memoizedState; + nextWorkInProgressHook = currentlyRenderingFiber.memoizedState; } else { nextWorkInProgressHook = workInProgressHook.next; } @@ -621,8 +618,7 @@ function updateWorkInProgressHook(): Hook { if (workInProgressHook === null) { // This is the first hook in the list. - let fiber = ((currentlyRenderingFiber: any): Fiber); - fiber.memoizedState = workInProgressHook = newHook; + currentlyRenderingFiber.memoizedState = workInProgressHook = newHook; } else { // Append to the end of the list. workInProgressHook = workInProgressHook.next = newHook; @@ -662,8 +658,7 @@ function mountReducer( }); const dispatch: Dispatch = (queue.dispatch = (dispatchAction.bind( null, - // Flow doesn't know this is non-null, but we do. - ((currentlyRenderingFiber: any): Fiber), + currentlyRenderingFiber, queue, ): any)); return [hook.memoizedState, dispatch]; @@ -762,9 +757,8 @@ function updateReducer( newBaseState = newState; } // Update the remaining priority in the queue. - let fiber = ((currentlyRenderingFiber: any): Fiber); - if (updateExpirationTime > fiber.expirationTime) { - fiber.expirationTime = updateExpirationTime; + if (updateExpirationTime > currentlyRenderingFiber.expirationTime) { + currentlyRenderingFiber.expirationTime = updateExpirationTime; markUnprocessedUpdateTime(updateExpirationTime); } } else { @@ -835,8 +829,7 @@ function mountState( BasicStateAction, > = (queue.dispatch = (dispatchAction.bind( null, - // Flow doesn't know this is non-null, but we do. - ((currentlyRenderingFiber: any): Fiber), + currentlyRenderingFiber, queue, ): any)); return [hook.memoizedState, dispatch]; @@ -857,10 +850,10 @@ function pushEffect(tag, create, destroy, deps) { // Circular next: (null: any), }; - let fiber = ((currentlyRenderingFiber: any): Fiber); - let componentUpdateQueue: null | FunctionComponentUpdateQueue = (fiber.updateQueue: any); + let componentUpdateQueue: null | FunctionComponentUpdateQueue = (currentlyRenderingFiber.updateQueue: any); if (componentUpdateQueue === null) { - (fiber: any).updateQueue = componentUpdateQueue = createFunctionComponentUpdateQueue(); + componentUpdateQueue = createFunctionComponentUpdateQueue(); + currentlyRenderingFiber.updateQueue = (componentUpdateQueue: any); componentUpdateQueue.lastEffect = effect.next = effect; } else { const lastEffect = componentUpdateQueue.lastEffect; @@ -894,8 +887,7 @@ function updateRef(initialValue: T): {current: T} { function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void { const hook = mountWorkInProgressHook(); const nextDeps = deps === undefined ? null : deps; - let fiber = ((currentlyRenderingFiber: any): Fiber); - fiber.effectTag |= fiberEffectTag; + currentlyRenderingFiber.effectTag |= fiberEffectTag; hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps); } @@ -916,8 +908,7 @@ function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void { } } - let fiber = ((currentlyRenderingFiber: any): Fiber); - fiber.effectTag |= fiberEffectTag; + currentlyRenderingFiber.effectTag |= fiberEffectTag; hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps); } @@ -930,7 +921,7 @@ function mountEffect( // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests if ('undefined' !== typeof jest) { warnIfNotCurrentlyActingEffectsInDEV( - ((currentlyRenderingFiber: any): Fiber), + currentlyRenderingFiber, ); } } @@ -950,7 +941,7 @@ function updateEffect( // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests if ('undefined' !== typeof jest) { warnIfNotCurrentlyActingEffectsInDEV( - ((currentlyRenderingFiber: any): Fiber), + currentlyRenderingFiber, ); } }