@@ -72,28 +72,28 @@ class TransitionComponent extends React.Component<
72
72
return null ;
73
73
}
74
74
75
- // getSnapshotBeforeUpdate(prevProps) {
76
- // let nextStatus = null
77
-
78
- // if (prevProps !== this.props) {
79
- // const { status } = this.state
80
-
81
- // if (this.props.in) {
82
- // if (status !== ENTERING && status !== ENTERED) {
83
- // nextStatus = ENTERING
84
- // }
85
- // } else {
86
- // if (status === ENTERING || status === ENTERED) {
87
- // nextStatus = EXITING
88
- // }
89
- // }
90
- // }
91
-
92
- // return { nextStatus }
75
+ // getSnapshotBeforeUpdate(prevProps: TransitionProps ) {
76
+ // let nextStatus = null;
77
+
78
+ // if (prevProps !== this.props) {
79
+ // const { status } = this.state;
80
+
81
+ // if (this.props.in) {
82
+ // if (status !== ENTERING && status !== ENTERED) {
83
+ // nextStatus = ENTERING;
84
+ // }
85
+ // } else {
86
+ // if (status === ENTERING || status === ENTERED) {
87
+ // nextStatus = EXITING;
88
+ // }
89
+ // }
90
+ // }
91
+
92
+ // return { nextStatus };
93
93
// }
94
94
95
95
componentDidMount ( ) {
96
- const node = this . props . nodeRef ?. current ;
96
+ const node = this . node ;
97
97
const status =
98
98
this . props . in ?
99
99
this . props . appear ?
@@ -105,7 +105,7 @@ class TransitionComponent extends React.Component<
105
105
}
106
106
107
107
componentDidUpdate ( prevProps : TransitionProps ) {
108
- let nextStatus = null ;
108
+ let nextStatus : TransitionStatus | null = null ;
109
109
if ( prevProps !== this . props ) {
110
110
const { status } = this . state ;
111
111
@@ -120,10 +120,12 @@ class TransitionComponent extends React.Component<
120
120
}
121
121
}
122
122
this . updateStatus ( false , nextStatus ) ;
123
+ this . props . onUpdated ?.( this . node , nextStatus , this . state . status ) ;
123
124
}
124
125
125
126
componentWillUnmount ( ) {
126
127
this . cancelNextCallback ( ) ;
128
+ this . props . onBeforeUnmount ?.( this . node , this . state . status ) ;
127
129
}
128
130
129
131
private get timeouts ( ) {
@@ -565,6 +567,27 @@ export interface TransitionProps {
565
567
* @param {"appear" | "enter" | "exit" } status - The component is appear, enter or exit.
566
568
*/
567
569
onMounted ?: ( node : HTMLElement , status : TransitionType ) => void ;
570
+
571
+ /**
572
+ * Callback fired after the component's state has been updated.
573
+ *
574
+ * @param node - The nodeRef you specified.
575
+ * @param nextStatus - The next transition status.
576
+ * @param previousStatus - The previous transition status.
577
+ */
578
+ onUpdated ?: (
579
+ node : HTMLElement ,
580
+ nextStatus : TransitionStatus | null ,
581
+ previousStatus : TransitionStatus ,
582
+ ) => void ;
583
+
584
+ /**
585
+ * Callback fired before the component is unmounted.
586
+ *
587
+ * @param node - The nodeRef you specified.
588
+ * @param lastStatus - The last transition status.
589
+ */
590
+ onBeforeUnmount ?: ( node : HTMLElement , lastStatus : TransitionStatus ) => void ;
568
591
}
569
592
570
593
type TransitionEventPropKeys = {
0 commit comments