Skip to content

Commit

Permalink
[fixed] Carousel checks if it is mounted before setting state
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Scekic committed Jul 31, 2015
1 parent 191f2ee commit bae8ba9
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/Carousel.js
Expand Up @@ -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
});
}
}
}
});
Expand Down

0 comments on commit bae8ba9

Please sign in to comment.