@@ -147,12 +147,13 @@ export function genCSSMotion(config: CSSMotionConfig) {
147147 return getDOM ( nodeRef . current ) as HTMLElement ;
148148 }
149149
150- const [ status , statusStep , statusStyle , mergedVisible ] = useStatus (
150+ const [ getStatus , statusStep , statusStyle , mergedVisible ] = useStatus (
151151 supportMotion ,
152152 visible ,
153153 getDomElement ,
154154 props ,
155155 ) ;
156+ const status = getStatus ( ) ;
156157
157158 // Record whether content has rendered
158159 // Will return null for un-rendered even when `removeOnLeave={false}`
@@ -162,10 +163,26 @@ export function genCSSMotion(config: CSSMotionConfig) {
162163 }
163164
164165 // ====================== 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 , [ ] ) ;
169186
170187 // ===================== Render =====================
171188 let motionChildren : React . ReactNode ;
0 commit comments