Skip to content

Commit 2e40ffb

Browse files
author
dylan.zeng
committed
🐞fix(carousel): hooks cannot use in conditions
1 parent fef86c9 commit 2e40ffb

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/components/carousel/index.tsx

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,27 @@ export const Carousel: FunctionComponent<CarouselProps> = (userProps: CarouselPr
5252
const autoSwipeTimer = useRef<number>();
5353
const isNavigation = typeof props.navigation === 'function';
5454

55-
if (props.dynamic) {
56-
useEffect(() => {
57-
const newItems = updateNodes(
58-
itemsRef.current,
59-
props.children,
60-
prevChildren,
61-
props.slide,
62-
props.infinite,
63-
);
55+
useEffect(() => {
56+
if (props.dynamic) return
57+
const newItems = updateNodes(
58+
itemsRef.current,
59+
props.children,
60+
prevChildren,
61+
props.slide,
62+
props.infinite,
63+
);
6464

65-
setItems(newItems);
66-
itemsRef.current = newItems;
67-
if (
68-
page < props.pageCount &&
69-
prevChildren &&
70-
prevChildren?.length < props.children.length
71-
) {
72-
slide(SlideDirection.Right);
73-
setPage(page + 1);
74-
}
75-
}, [props.children]);
76-
}
65+
setItems(newItems);
66+
itemsRef.current = newItems;
67+
if (
68+
page < props.pageCount &&
69+
prevChildren &&
70+
prevChildren?.length < props.children.length
71+
) {
72+
slide(SlideDirection.Right);
73+
setPage(page + 1);
74+
}
75+
}, [props.children]);
7776

7877
useEffect(() => {
7978
autoSwipe();

0 commit comments

Comments
 (0)