Skip to content

Commit

Permalink
chore : autoplay 원래있던 기능 대로 복구
Browse files Browse the repository at this point in the history
  • Loading branch information
godhyzzang committed Nov 29, 2024
1 parent 4c3269a commit efe7037
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/components/common/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function Carousel<T>({
const [isTransitioning, setIsTransitioning] = useState(false);
const carouselRef = useRef<HTMLDivElement>(null);
const touchStartX = useRef<number | null>(null);
const intervalRef = useRef<number | null>(null);
const intervalRef = useRef<NodeJS.Timeout | null>(null);

const gap = 16; // 아이템 간 간격 (px)
const totalItems = previewDatas.length;
Expand Down Expand Up @@ -91,16 +91,17 @@ export default function Carousel<T>({

useEffect(() => {
if (isAutoPlay && intervalRef.current === null) {
const intervalId = window.setInterval(nextSlide, autoPlayInterval);
const intervalId = setInterval(nextSlide, autoPlayInterval);
intervalRef.current = intervalId;
}
// 종속배열 바뀔 때마다 실행
return () => {
if (intervalRef.current !== null) {
if (intervalRef.current) {
clearInterval(intervalRef.current);
intervalRef.current = null;
}
};
}, [isAutoPlay, autoPlayInterval, nextSlide]);
}, [isAutoPlay, nextSlide]);

const handleTouchStart = (event: React.TouchEvent) => {
touchStartX.current = event.touches[0].clientX;
Expand Down

0 comments on commit efe7037

Please sign in to comment.