Skip to content

Commit

Permalink
fix(Modal): clear timeouts when toggling of modal - #166
Browse files Browse the repository at this point in the history
  • Loading branch information
ajainarayanan authored and eddywashere committed Dec 12, 2016
1 parent 9456d10 commit 5e0f5d2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Fade.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ class Fade extends React.Component {

this.onLeave = this.onLeave.bind(this);
this.onEnter = this.onEnter.bind(this);
this.timers = [];
}

componentWillUnmount() {
this.timers.forEach(timer => clearTimeout(timer));
}
onEnter(cb) {
return () => {
cb();
Expand All @@ -51,7 +55,6 @@ class Fade extends React.Component {
}
};
}

onLeave(cb) {
return () => {
cb();
Expand All @@ -66,7 +69,7 @@ class Fade extends React.Component {
this.onEnter(cb)();
}

setTimeout(this.onEnter(cb), this.props.transitionAppearTimeout);
this.timers.push(setTimeout(this.onEnter(cb), this.props.transitionAppearTimeout));
}

componentDidAppear() {
Expand All @@ -80,7 +83,7 @@ class Fade extends React.Component {
this.onEnter(cb)();
}

setTimeout(this.onEnter(cb), this.props.transitionEnterTimeout);
this.timers.push(setTimeout(this.onEnter(cb), this.props.transitionEnterTimeout));
}

componentDidEnter() {
Expand All @@ -98,9 +101,8 @@ class Fade extends React.Component {
this.onLeave(cb)();
}

setTimeout(this.onLeave(cb), this.props.transitionLeaveTimeout);
this.timers.push(setTimeout(this.onLeave(cb), this.props.transitionLeaveTimeout));
}

render() {
const {
baseClass,
Expand Down

0 comments on commit 5e0f5d2

Please sign in to comment.