Skip to content

Commit bae8ba9

Browse files
author
Igor Scekic
committed
[fixed] Carousel checks if it is mounted before setting state
1 parent 191f2ee commit bae8ba9

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

Diff for: src/Carousel.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -266,26 +266,28 @@ const Carousel = React.createClass({
266266
handleSelect(index, direction) {
267267
clearTimeout(this.timeout);
268268

269-
let previousActiveIndex = this.getActiveIndex();
270-
direction = direction || this.getDirection(previousActiveIndex, index);
269+
if (this.isMounted()) {
270+
let previousActiveIndex = this.getActiveIndex();
271+
direction = direction || this.getDirection(previousActiveIndex, index);
271272

272-
if (this.props.onSelect) {
273-
this.props.onSelect(index, direction);
274-
}
275-
276-
if (this.props.activeIndex == null && index !== previousActiveIndex) {
277-
if (this.state.previousActiveIndex != null) {
278-
// If currently animating don't activate the new index.
279-
// TODO: look into queuing this canceled call and
280-
// animating after the current animation has ended.
281-
return;
273+
if (this.props.onSelect) {
274+
this.props.onSelect(index, direction);
282275
}
283276

284-
this.setState({
285-
activeIndex: index,
286-
previousActiveIndex,
287-
direction
288-
});
277+
if (this.props.activeIndex == null && index !== previousActiveIndex) {
278+
if (this.state.previousActiveIndex != null) {
279+
// If currently animating don't activate the new index.
280+
// TODO: look into queuing this canceled call and
281+
// animating after the current animation has ended.
282+
return;
283+
}
284+
285+
this.setState({
286+
activeIndex: index,
287+
previousActiveIndex,
288+
direction
289+
});
290+
}
289291
}
290292
}
291293
});

0 commit comments

Comments
 (0)