Skip to content

Commit

Permalink
Merge pull request #55 from erichbehrens/fix/clear-timeout-on-unmount
Browse files Browse the repository at this point in the history
Clear timeout on component unmount
  • Loading branch information
erichbehrens committed Jul 4, 2018
2 parents 5aa8fb5 + dd2e95e commit 17854c9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-animated-slider",
"version": "1.1.2",
"version": "1.1.3",
"description": "Animated slider component for react",
"main": "build/index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Slider extends React.PureComponent {

componentWillUnmount() {
this.stopAutoplay();
if (this.animationTimerId) {
clearTimeout(this.animationTimerId);
}
}

setupAutoplay = () => {
Expand Down Expand Up @@ -102,7 +105,8 @@ class Slider extends React.PureComponent {
if (this.isDisabled()) return;
this.nextSlideIndex = index;
this.setState({ animating: true, animation });
setTimeout(this.onAnimationEnd, this.props.duration || DEFAULT_DURATION);
const timeout = this.props.duration || DEFAULT_DURATION;
this.animationTimerId = setTimeout(this.onAnimationEnd, timeout);
};

previous = () => {
Expand Down

0 comments on commit 17854c9

Please sign in to comment.