Skip to content

Commit 5e0f5d2

Browse files
ajainarayananeddywashere
authored andcommitted
fix(Modal): clear timeouts when toggling of modal - #166
1 parent 9456d10 commit 5e0f5d2

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/Fade.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ class Fade extends React.Component {
4141

4242
this.onLeave = this.onLeave.bind(this);
4343
this.onEnter = this.onEnter.bind(this);
44+
this.timers = [];
4445
}
4546

47+
componentWillUnmount() {
48+
this.timers.forEach(timer => clearTimeout(timer));
49+
}
4650
onEnter(cb) {
4751
return () => {
4852
cb();
@@ -51,7 +55,6 @@ class Fade extends React.Component {
5155
}
5256
};
5357
}
54-
5558
onLeave(cb) {
5659
return () => {
5760
cb();
@@ -66,7 +69,7 @@ class Fade extends React.Component {
6669
this.onEnter(cb)();
6770
}
6871

69-
setTimeout(this.onEnter(cb), this.props.transitionAppearTimeout);
72+
this.timers.push(setTimeout(this.onEnter(cb), this.props.transitionAppearTimeout));
7073
}
7174

7275
componentDidAppear() {
@@ -80,7 +83,7 @@ class Fade extends React.Component {
8083
this.onEnter(cb)();
8184
}
8285

83-
setTimeout(this.onEnter(cb), this.props.transitionEnterTimeout);
86+
this.timers.push(setTimeout(this.onEnter(cb), this.props.transitionEnterTimeout));
8487
}
8588

8689
componentDidEnter() {
@@ -98,9 +101,8 @@ class Fade extends React.Component {
98101
this.onLeave(cb)();
99102
}
100103

101-
setTimeout(this.onLeave(cb), this.props.transitionLeaveTimeout);
104+
this.timers.push(setTimeout(this.onLeave(cb), this.props.transitionLeaveTimeout));
102105
}
103-
104106
render() {
105107
const {
106108
baseClass,

0 commit comments

Comments
 (0)