From bae8ba9e2e8eb229b144cc9f0a423f6ce63f9caf Mon Sep 17 00:00:00 2001 From: Igor Scekic Date: Wed, 29 Jul 2015 16:37:46 +0200 Subject: [PATCH] [fixed] Carousel checks if it is mounted before setting state --- src/Carousel.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Carousel.js b/src/Carousel.js index 0d1b21adb0..8801661c2d 100644 --- a/src/Carousel.js +++ b/src/Carousel.js @@ -266,26 +266,28 @@ const Carousel = React.createClass({ handleSelect(index, direction) { clearTimeout(this.timeout); - let previousActiveIndex = this.getActiveIndex(); - direction = direction || this.getDirection(previousActiveIndex, index); + if (this.isMounted()) { + let previousActiveIndex = this.getActiveIndex(); + direction = direction || this.getDirection(previousActiveIndex, index); - if (this.props.onSelect) { - this.props.onSelect(index, direction); - } - - if (this.props.activeIndex == null && index !== previousActiveIndex) { - if (this.state.previousActiveIndex != null) { - // If currently animating don't activate the new index. - // TODO: look into queuing this canceled call and - // animating after the current animation has ended. - return; + if (this.props.onSelect) { + this.props.onSelect(index, direction); } - this.setState({ - activeIndex: index, - previousActiveIndex, - direction - }); + if (this.props.activeIndex == null && index !== previousActiveIndex) { + if (this.state.previousActiveIndex != null) { + // If currently animating don't activate the new index. + // TODO: look into queuing this canceled call and + // animating after the current animation has ended. + return; + } + + this.setState({ + activeIndex: index, + previousActiveIndex, + direction + }); + } } } });