@@ -89,8 +89,8 @@ type Update<S, A> = {
8989type UpdateQueue < S , A > = {
9090 last : Update < S , A> | null ,
9191 dispatch : ( A => mixed ) | null ,
92- eagerReducer : ( ( S , A ) => S ) | null ,
93- eagerState : S | null ,
92+ lastRenderedReducer : ( ( S , A ) => S ) | null ,
93+ lastRenderedState : S | null ,
9494} ;
9595
9696export type HookType =
@@ -603,8 +603,8 @@ function mountReducer<S, I, A>(
603603 const queue = (hook.queue = {
604604 last : null ,
605605 dispatch : null ,
606- eagerReducer : reducer ,
607- eagerState : ( initialState : any ) ,
606+ lastRenderedReducer : reducer ,
607+ lastRenderedState : ( initialState : any ) ,
608608 } );
609609 const dispatch: Dispatch< A > = (queue.dispatch = (dispatchAction.bind(
610610 null,
@@ -627,6 +627,8 @@ function updateReducer<S, I, A>(
627627 'Should have a queue. This is likely a bug in React. Please file an issue.' ,
628628 ) ;
629629
630+ queue . lastRenderedReducer = reducer ;
631+
630632 if ( numberOfReRenders > 0 ) {
631633 // This is a re-render. Apply the new render phase updates to the previous
632634 // work-in-progress hook.
@@ -662,8 +664,7 @@ function updateReducer<S, I, A>(
662664 hook . baseState = newState ;
663665 }
664666
665- queue . eagerReducer = reducer ;
666- queue . eagerState = newState ;
667+ queue . lastRenderedState = newState ;
667668
668669 return [ newState , dispatch ] ;
669670 }
@@ -742,8 +743,7 @@ function updateReducer<S, I, A>(
742743 hook.baseUpdate = newBaseUpdate;
743744 hook.baseState = newBaseState;
744745
745- queue.eagerReducer = reducer;
746- queue.eagerState = newState;
746+ queue.lastRenderedState = newState;
747747 }
748748
749749 const dispatch : Dispatch < A > = (queue.dispatch: any);
@@ -761,8 +761,8 @@ function mountState<S>(
761761 const queue = (hook.queue = {
762762 last : null ,
763763 dispatch : null ,
764- eagerReducer : basicStateReducer ,
765- eagerState : ( initialState : any ) ,
764+ lastRenderedReducer : basicStateReducer ,
765+ lastRenderedState : ( initialState : any ) ,
766766 } );
767767 const dispatch: Dispatch<
768768 BasicStateAction < S > ,
@@ -1141,21 +1141,21 @@ function dispatchAction<S, A>(
11411141 // The queue is currently empty, which means we can eagerly compute the
11421142 // next state before entering the render phase. If the new state is the
11431143 // same as the current state, we may be able to bail out entirely.
1144- const eagerReducer = queue . eagerReducer ;
1145- if ( eagerReducer !== null ) {
1144+ const lastRenderedReducer = queue . lastRenderedReducer ;
1145+ if ( lastRenderedReducer !== null ) {
11461146 let prevDispatcher ;
11471147 if ( __DEV__ ) {
11481148 prevDispatcher = ReactCurrentDispatcher . current ;
11491149 ReactCurrentDispatcher . current = InvalidNestedHooksDispatcherOnUpdateInDEV ;
11501150 }
11511151 try {
1152- const currentState : S = ( queue . eagerState : any ) ;
1153- const eagerState = eagerReducer ( currentState , action ) ;
1152+ const currentState : S = ( queue . lastRenderedState : any ) ;
1153+ const eagerState = lastRenderedReducer ( currentState , action ) ;
11541154 // Stash the eagerly computed state, and the reducer used to compute
11551155 // it, on the update object. If the reducer hasn't changed by the
11561156 // time we enter the render phase, then the eager state can be used
11571157 // without calling the reducer again.
1158- update . eagerReducer = eagerReducer ;
1158+ update . eagerReducer = lastRenderedReducer ;
11591159 update . eagerState = eagerState ;
11601160 if ( is ( eagerState , currentState ) ) {
11611161 // Fast path. We can bail out without scheduling React to re-render.
0 commit comments