@@ -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 =
@@ -591,8 +591,8 @@ function mountReducer<S, I, A>(
591
591
const queue = (hook.queue = {
592
592
last : null ,
593
593
dispatch : null ,
594
- eagerReducer : reducer ,
595
- eagerState : ( initialState : any ) ,
594
+ lastRenderedReducer : reducer ,
595
+ lastRenderedState : ( initialState : any ) ,
596
596
} );
597
597
const dispatch: Dispatch< A > = (queue.dispatch = (dispatchAction.bind(
598
598
null,
@@ -615,6 +615,8 @@ function updateReducer<S, I, A>(
615
615
'Should have a queue. This is likely a bug in React. Please file an issue.' ,
616
616
) ;
617
617
618
+ queue . lastRenderedReducer = reducer ;
619
+
618
620
if ( numberOfReRenders > 0 ) {
619
621
// This is a re-render. Apply the new render phase updates to the previous
620
622
// work-in-progress hook.
@@ -650,8 +652,7 @@ function updateReducer<S, I, A>(
650
652
hook . baseState = newState ;
651
653
}
652
654
653
- queue . eagerReducer = reducer ;
654
- queue . eagerState = newState ;
655
+ queue . lastRenderedState = newState ;
655
656
656
657
return [ newState , dispatch ] ;
657
658
}
@@ -730,8 +731,7 @@ function updateReducer<S, I, A>(
730
731
hook.baseUpdate = newBaseUpdate;
731
732
hook.baseState = newBaseState;
732
733
733
- queue.eagerReducer = reducer;
734
- queue.eagerState = newState;
734
+ queue.lastRenderedState = newState;
735
735
}
736
736
737
737
const dispatch : Dispatch < A > = (queue.dispatch: any);
@@ -749,8 +749,8 @@ function mountState<S>(
749
749
const queue = (hook.queue = {
750
750
last : null ,
751
751
dispatch : null ,
752
- eagerReducer : basicStateReducer ,
753
- eagerState : ( initialState : any ) ,
752
+ lastRenderedReducer : basicStateReducer ,
753
+ lastRenderedState : ( initialState : any ) ,
754
754
} );
755
755
const dispatch: Dispatch<
756
756
BasicStateAction < S > ,
@@ -1129,21 +1129,21 @@ function dispatchAction<S, A>(
1129
1129
// The queue is currently empty, which means we can eagerly compute the
1130
1130
// next state before entering the render phase. If the new state is the
1131
1131
// same as the current state, we may be able to bail out entirely.
1132
- const eagerReducer = queue . eagerReducer ;
1133
- if ( eagerReducer !== null ) {
1132
+ const lastRenderedReducer = queue . lastRenderedReducer ;
1133
+ if ( lastRenderedReducer !== null ) {
1134
1134
let prevDispatcher ;
1135
1135
if ( __DEV__ ) {
1136
1136
prevDispatcher = ReactCurrentDispatcher . current ;
1137
1137
ReactCurrentDispatcher . current = InvalidNestedHooksDispatcherOnUpdateInDEV ;
1138
1138
}
1139
1139
try {
1140
- const currentState : S = ( queue . eagerState : any ) ;
1141
- const eagerState = eagerReducer ( currentState , action ) ;
1140
+ const currentState : S = ( queue . lastRenderedState : any ) ;
1141
+ const eagerState = lastRenderedReducer ( currentState , action ) ;
1142
1142
// Stash the eagerly computed state, and the reducer used to compute
1143
1143
// it, on the update object. If the reducer hasn't changed by the
1144
1144
// time we enter the render phase, then the eager state can be used
1145
1145
// without calling the reducer again.
1146
- update . eagerReducer = eagerReducer ;
1146
+ update . eagerReducer = lastRenderedReducer ;
1147
1147
update . eagerState = eagerState ;
1148
1148
if ( is ( eagerState , currentState ) ) {
1149
1149
// Fast path. We can bail out without scheduling React to re-render.
0 commit comments