@@ -110,21 +110,31 @@ export function genCSSMotionList(
110110
111111 // ZombieJ: Return the count of rest keys. It's safe to refactor if need more info.
112112 removeKey = ( removeKey : React . Key ) => {
113- const { keyEntities } = this . state ;
114- const nextKeyEntities = keyEntities . map ( entity => {
115- if ( entity . key !== removeKey ) return entity ;
116- return {
117- ...entity ,
118- status : STATUS_REMOVED ,
119- } ;
120- } ) ;
121-
122- this . setState ( {
123- keyEntities : nextKeyEntities ,
124- } ) ;
125-
126- return nextKeyEntities . filter ( ( { status } ) => status !== STATUS_REMOVED )
127- . length ;
113+ this . setState (
114+ prevState => {
115+ const nextKeyEntities = prevState . keyEntities . map ( entity => {
116+ if ( entity . key !== removeKey ) return entity ;
117+ return {
118+ ...entity ,
119+ status : STATUS_REMOVED ,
120+ } ;
121+ } ) ;
122+
123+ return {
124+ keyEntities : nextKeyEntities ,
125+ } ;
126+ } ,
127+ ( ) => {
128+ const { keyEntities } = this . state ;
129+ const restKeysCount = keyEntities . filter (
130+ ( { status } ) => status !== STATUS_REMOVED ,
131+ ) . length ;
132+
133+ if ( restKeysCount === 0 && this . props . onAllRemoved ) {
134+ this . props . onAllRemoved ( ) ;
135+ }
136+ } ,
137+ ) ;
128138 } ;
129139
130140 render ( ) {
@@ -160,11 +170,7 @@ export function genCSSMotionList(
160170 onVisibleChanged ?.( changedVisible , { key : eventProps . key } ) ;
161171
162172 if ( ! changedVisible ) {
163- const restKeysCount = this . removeKey ( eventProps . key ) ;
164-
165- if ( restKeysCount === 0 && onAllRemoved ) {
166- onAllRemoved ( ) ;
167- }
173+ this . removeKey ( eventProps . key ) ;
168174 }
169175 } }
170176 >
0 commit comments