1- import { useState , useEffect , useRef , useMemo } from 'react' ;
1+ import { useState , useEffect , useMemo } from 'react' ;
22import { useIsoEffect } from './useIsoEffect' ;
33
44/**
@@ -101,7 +101,9 @@ export type TransitionProps = {
101101 * @param activePhase - The phase currently in progress (e.g., "appearActive", "enterDone").
102102 * @returns React nodes to render.
103103 */
104- children : ( transitionState : TransitionState , activePhase : TransitionPhase ) => React . ReactNode ;
104+ children :
105+ | React . ReactNode
106+ | ( ( transitionState : TransitionState , activePhase : TransitionPhase ) => React . ReactNode ) ;
105107} ;
106108
107109const EVENT_MAP : {
@@ -136,7 +138,6 @@ export function Transition(props: TransitionProps) {
136138 addEndListener,
137139 } = props ;
138140
139- const tmRef = useRef < number > ( 0 ) ;
140141 let ignoreInPropChange = false ;
141142
142143 // Make phase state
@@ -157,19 +158,20 @@ export function Transition(props: TransitionProps) {
157158 const [ eventName , nextPhase , delay ] = EVENT_MAP [ phase ] ;
158159 const { [ eventName ] : event } = props ;
159160 event ?.( ) ;
161+ let tm = 0 ;
160162 if ( nextPhase ) {
161163 if ( delay ) {
162164 if ( addEndListener ) {
163165 addEndListener ( phase , ( ) => setPhase ( nextPhase ) ) ;
164166 } else {
165- tmRef . current = setTimeout ( setPhase , duration , nextPhase ) ;
167+ tm = setTimeout ( setPhase , duration , nextPhase ) ;
166168 }
167169 } else {
168- tmRef . current = setTimeout ( setPhase , 0 , nextPhase ) ;
170+ tm = setTimeout ( setPhase , 0 , nextPhase ) ;
169171 }
170172 }
171173 return ( ) => {
172- clearTimeout ( tmRef . current ) ;
174+ clearTimeout ( tm ) ;
173175 } ;
174176 } , [ phase , duration ] ) ;
175177
@@ -195,10 +197,10 @@ export function Transition(props: TransitionProps) {
195197 ) ;
196198
197199 // Do not render anything
198- if ( ! alwaysMounted && phase === TransitionPhase . EXIT_DONE ) {
200+ if ( ! alwaysMounted && ( exit ? phase === TransitionPhase . EXIT_DONE : ! inProp ) ) {
199201 return null ;
200202 }
201203
202204 // Render children
203- return children ( transitionState , phase ) ;
205+ return typeof children === 'function' ? children ( transitionState , phase ) : children ;
204206}
0 commit comments