@@ -89,8 +89,8 @@ type Update<S, A> = {
89
89
type UpdateQueue < S , A > = {
90
90
last : Update < S , A> | null ,
91
91
dispatch : ( A => mixed ) | null ,
92
- eagerReducer : ( ( S , A ) => S ) | null ,
93
- eagerState : S | null ,
92
+ lastRenderedReducer : ( ( S , A ) => S ) | null ,
93
+ lastRenderedState : S | null ,
94
94
} ;
95
95
96
96
export type HookType =
@@ -603,8 +603,8 @@ function mountReducer<S, I, A>(
603
603
const queue = (hook.queue = {
604
604
last : null ,
605
605
dispatch : null ,
606
- eagerReducer : reducer ,
607
- eagerState : ( initialState : any ) ,
606
+ lastRenderedReducer : reducer ,
607
+ lastRenderedState : ( initialState : any ) ,
608
608
} );
609
609
const dispatch: Dispatch< A > = (queue.dispatch = (dispatchAction.bind(
610
610
null,
@@ -627,6 +627,8 @@ function updateReducer<S, I, A>(
627
627
'Should have a queue. This is likely a bug in React. Please file an issue.' ,
628
628
) ;
629
629
630
+ queue . lastRenderedReducer = reducer ;
631
+
630
632
if ( numberOfReRenders > 0 ) {
631
633
// This is a re-render. Apply the new render phase updates to the previous
632
634
// work-in-progress hook.
@@ -662,8 +664,7 @@ function updateReducer<S, I, A>(
662
664
hook . baseState = newState ;
663
665
}
664
666
665
- queue . eagerReducer = reducer ;
666
- queue . eagerState = newState ;
667
+ queue . lastRenderedState = newState ;
667
668
668
669
return [ newState , dispatch ] ;
669
670
}
@@ -742,8 +743,7 @@ function updateReducer<S, I, A>(
742
743
hook.baseUpdate = newBaseUpdate;
743
744
hook.baseState = newBaseState;
744
745
745
- queue.eagerReducer = reducer;
746
- queue.eagerState = newState;
746
+ queue.lastRenderedState = newState;
747
747
}
748
748
749
749
const dispatch : Dispatch < A > = (queue.dispatch: any);
@@ -761,8 +761,8 @@ function mountState<S>(
761
761
const queue = (hook.queue = {
762
762
last : null ,
763
763
dispatch : null ,
764
- eagerReducer : basicStateReducer ,
765
- eagerState : ( initialState : any ) ,
764
+ lastRenderedReducer : basicStateReducer ,
765
+ lastRenderedState : ( initialState : any ) ,
766
766
} );
767
767
const dispatch: Dispatch<
768
768
BasicStateAction < S > ,
@@ -1141,21 +1141,21 @@ function dispatchAction<S, A>(
1141
1141
// The queue is currently empty, which means we can eagerly compute the
1142
1142
// next state before entering the render phase. If the new state is the
1143
1143
// 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 ) {
1146
1146
let prevDispatcher ;
1147
1147
if ( __DEV__ ) {
1148
1148
prevDispatcher = ReactCurrentDispatcher . current ;
1149
1149
ReactCurrentDispatcher . current = InvalidNestedHooksDispatcherOnUpdateInDEV ;
1150
1150
}
1151
1151
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 ) ;
1154
1154
// Stash the eagerly computed state, and the reducer used to compute
1155
1155
// it, on the update object. If the reducer hasn't changed by the
1156
1156
// time we enter the render phase, then the eager state can be used
1157
1157
// without calling the reducer again.
1158
- update . eagerReducer = eagerReducer ;
1158
+ update . eagerReducer = lastRenderedReducer ;
1159
1159
update . eagerState = eagerState ;
1160
1160
if ( is ( eagerState , currentState ) ) {
1161
1161
// Fast path. We can bail out without scheduling React to re-render.
0 commit comments