@@ -41,11 +41,6 @@ type VisibleElement = {
4141 removeTimeout ?: number ;
4242} ;
4343
44- const getChildProp = < T , > ( child : React . ReactElement < any > , propName : string , defaultValue : T ) : T => {
45- const { [ propName ] : prop = defaultValue } = child . props ;
46- return prop ;
47- } ;
48-
4944/**
5045 * The `TransitionGroup` component handles a collection of `Transition` child elements
5146 * and applies transition animations when elements enter and exit the DOM.
@@ -69,37 +64,32 @@ export function TransitionGroup(props: TransitionGroupProps) {
6964 }
7065 } ) ;
7166
72- const pushVisibleElement = (
67+ const addVisibleElement = (
7368 element : VisibleElement [ 'element' ] ,
7469 removeTimeout ?: VisibleElement [ 'removeTimeout' ] ,
7570 ) => {
7671 const elementClone = cloneElement ( element , {
77- exit,
78- enter,
79- duration,
8072 in : ! removeTimeout ,
81- appear : firstRenderRef . current
82- ? getChildProp ( element , 'appear' , appear )
83- : getChildProp ( element , 'enter' , enter ) ,
73+ enter : false ,
74+ appear : firstRenderRef . current ? ( element . props . appear ?? appear ) : ( element . props . enter ?? enter ) ,
75+ exit : element . props . exit ?? exit ,
76+ duration : element . props . duration ?? duration ,
8477 } ) ;
8578
8679 nextVisibleElements . push ( { element, removeTimeout } ) ;
8780 nextElements . push ( elementClone ) ;
8881 } ;
8982
9083 const makeRemoveTimeout = ( elementToRemove : VisibleElement [ 'element' ] ) =>
91- window . setTimeout (
92- ( ) => {
93- const { current : prevVisibleChildren } = prevVisibleElementsRef ;
94- const indexToDelete = prevVisibleChildren . findIndex (
95- ( { element } ) => element . key === elementToRemove . key ,
96- ) ;
97- if ( indexToDelete >= 0 ) {
98- prevVisibleChildren . splice ( indexToDelete , 1 ) ;
99- }
100- } ,
101- getChildProp ( elementToRemove , 'duration' , duration ) ,
102- ) ;
84+ window . setTimeout ( ( ) => {
85+ const { current : prevVisibleChildren } = prevVisibleElementsRef ;
86+ const indexToDelete = prevVisibleChildren . findIndex (
87+ ( { element } ) => element . key === elementToRemove . key ,
88+ ) ;
89+ if ( indexToDelete >= 0 ) {
90+ prevVisibleChildren . splice ( indexToDelete , 1 ) ;
91+ }
92+ } , elementToRemove . props . duration ?? duration ) ;
10393
10494 let lastAddedElementIndex = 0 ;
10595
@@ -111,12 +101,12 @@ export function TransitionGroup(props: TransitionGroupProps) {
111101 if ( foundIndex < 0 ) {
112102 // The visible element already has a removal timeout, which means it's currently exiting
113103 if ( prevRemoveTimeout ) {
114- pushVisibleElement ( prevElement , prevRemoveTimeout ) ;
104+ addVisibleElement ( prevElement , prevRemoveTimeout ) ;
115105 } else {
116106 // Start the removal timeout, but continue rendering this element
117- const shouldAddTimeout = exit && prevElement . props . exit !== false ;
107+ const shouldAddTimeout = prevElement . props . exit ?? exit ;
118108 if ( shouldAddTimeout ) {
119- pushVisibleElement ( prevElement , makeRemoveTimeout ( prevElement ) ) ;
109+ addVisibleElement ( prevElement , makeRemoveTimeout ( prevElement ) ) ;
120110 }
121111 }
122112 } else {
@@ -126,7 +116,7 @@ export function TransitionGroup(props: TransitionGroupProps) {
126116 }
127117 // Add derived element along with all previous children
128118 for ( let i = lastAddedElementIndex ; i <= foundIndex ; i += 1 ) {
129- pushVisibleElement ( derivedElements [ i ] ) ;
119+ addVisibleElement ( derivedElements [ i ] ) ;
130120 }
131121 }
132122 // Save the index to loop only through the remaining element
@@ -135,7 +125,7 @@ export function TransitionGroup(props: TransitionGroupProps) {
135125
136126 // Add the remaining elements
137127 for ( let i = lastAddedElementIndex ; i < derivedElements . length ; i += 1 ) {
138- pushVisibleElement ( derivedElements [ i ] ) ;
128+ addVisibleElement ( derivedElements [ i ] ) ;
139129 }
140130
141131 // Save the visible elements
0 commit comments