Skip to content

Commit 4ab4e48

Browse files
committed
Update more events and import types
1 parent efd5299 commit 4ab4e48

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

src/Transition.tsx

+43-20
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,28 @@ class TransitionComponent extends React.Component<
7272
return null;
7373
}
7474

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 };
9393
// }
9494

9595
componentDidMount() {
96-
const node = this.props.nodeRef?.current;
96+
const node = this.node;
9797
const status =
9898
this.props.in ?
9999
this.props.appear ?
@@ -105,7 +105,7 @@ class TransitionComponent extends React.Component<
105105
}
106106

107107
componentDidUpdate(prevProps: TransitionProps) {
108-
let nextStatus = null;
108+
let nextStatus: TransitionStatus | null = null;
109109
if (prevProps !== this.props) {
110110
const { status } = this.state;
111111

@@ -120,10 +120,12 @@ class TransitionComponent extends React.Component<
120120
}
121121
}
122122
this.updateStatus(false, nextStatus);
123+
this.props.onUpdated?.(this.node, nextStatus, this.state.status);
123124
}
124125

125126
componentWillUnmount() {
126127
this.cancelNextCallback();
128+
this.props.onBeforeUnmount?.(this.node, this.state.status);
127129
}
128130

129131
private get timeouts() {
@@ -565,6 +567,27 @@ export interface TransitionProps {
565567
* @param {"appear" | "enter" | "exit"} status - The component is appear, enter or exit.
566568
*/
567569
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;
568591
}
569592

570593
type TransitionEventPropKeys = {

src/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ export { default as SwitchTransition } from "./SwitchTransition";
44
export { default as TransitionGroup } from "./TransitionGroup";
55
export { default as Transition } from "./Transition";
66
export { default as config } from "./config";
7+
8+
export type * from "./CSSTransition";
9+
export type * from "./ReplaceTransition";
10+
export type * from "./SwitchTransition";
11+
export type * from "./TransitionGroup";
12+
export type * from "./Transition";

0 commit comments

Comments
 (0)