Skip to content

Commit

Permalink
fix: Fix clearing nextDirectionRef in <Carousel> (#5322)
Browse files Browse the repository at this point in the history
* fix: Fix clearing nextDirectionRef in <Carousel>

Fixes #5319

* fix
  • Loading branch information
taion committed Aug 5, 2020
1 parent 3c58d9a commit 5c5ea8d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ function CarouselFunc(uncontrolledProps: CarouselProps, ref) {
if (!isSliding && activeIndex !== renderedActiveIndex) {
if (nextDirectionRef.current) {
setDirection(nextDirectionRef.current);
nextDirectionRef.current = null;
} else {
setDirection((activeIndex || 0) > renderedActiveIndex ? 'next' : 'prev');
}
Expand All @@ -265,6 +264,12 @@ function CarouselFunc(uncontrolledProps: CarouselProps, ref) {
setRenderedActiveIndex(activeIndex || 0);
}

useEffect(() => {
if (nextDirectionRef.current) {
nextDirectionRef.current = null;
}
});

const numChildren = React.Children.toArray(children).filter(
React.isValidElement,
).length;
Expand Down

0 comments on commit 5c5ea8d

Please sign in to comment.