@@ -147,12 +147,13 @@ export function genCSSMotion(config: CSSMotionConfig) {
147
147
return getDOM ( nodeRef . current ) as HTMLElement ;
148
148
}
149
149
150
- const [ status , statusStep , statusStyle , mergedVisible ] = useStatus (
150
+ const [ getStatus , statusStep , statusStyle , mergedVisible ] = useStatus (
151
151
supportMotion ,
152
152
visible ,
153
153
getDomElement ,
154
154
props ,
155
155
) ;
156
+ const status = getStatus ( ) ;
156
157
157
158
// Record whether content has rendered
158
159
// Will return null for un-rendered even when `removeOnLeave={false}`
@@ -162,10 +163,26 @@ export function genCSSMotion(config: CSSMotionConfig) {
162
163
}
163
164
164
165
// ====================== Refs ======================
165
- React . useImperativeHandle ( ref , ( ) => ( {
166
- nativeElement : getDomElement ( ) ,
167
- inMotion : ( ) => status !== STATUS_NONE ,
168
- } ) ) ;
166
+ const refObj = React . useMemo < CSSMotionRef > ( ( ) => {
167
+ const obj = { } as CSSMotionRef ;
168
+ Object . defineProperties ( obj , {
169
+ nativeElement : {
170
+ enumerable : true ,
171
+ get : getDomElement ,
172
+ } ,
173
+ inMotion : {
174
+ enumerable : true ,
175
+ get : ( ) => {
176
+ return ( ) => getStatus ( ) !== STATUS_NONE ;
177
+ } ,
178
+ } ,
179
+ } ) ;
180
+ return obj ;
181
+ } , [ ] ) ;
182
+
183
+ // We lock `deps` here since function return object
184
+ // will repeat trigger ref from `refConfig` -> `null` -> `refConfig`
185
+ React . useImperativeHandle ( ref , ( ) => refObj , [ ] ) ;
169
186
170
187
// ===================== Render =====================
171
188
let motionChildren : React . ReactNode ;
0 commit comments