Skip to content

Commit 9287b96

Browse files
only update state if needed
1 parent bea008d commit 9287b96

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

dotcom-rendering/src/components/ScrollableCarousel.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,12 @@ export const ScrollableCarousel = ({
362362
const carouselElement = carouselRef.current;
363363
if (!carouselElement) return;
364364
const cardWidth = carouselElement.querySelector('li')?.offsetWidth ?? 0;
365-
setCardCount(
366-
Math.ceil((carouselElement.scrollLeft + cardWidth / 2) / cardWidth),
365+
const count = Math.ceil(
366+
(carouselElement.scrollLeft + cardWidth / 2) / cardWidth,
367367
);
368+
if (count !== cardCount) {
369+
setCardCount(count);
370+
}
368371
};
369372

370373
/**

0 commit comments

Comments
 (0)