diff --git a/apps/spa/src/components/ProductImageGallery.tsx b/apps/spa/src/components/ProductImageGallery.tsx index 403d9f1..bd322f5 100644 --- a/apps/spa/src/components/ProductImageGallery.tsx +++ b/apps/spa/src/components/ProductImageGallery.tsx @@ -12,15 +12,15 @@ export default function ProductImageGallery({ images, fallback, alt = 'Product I const [currentIndex, setCurrentIndex] = useState(0) const scrollRef = useRef(null) - useEffect(() => { + const handleThumbnailClick = (idx: number) => { + setCurrentIndex(idx) if (scrollRef.current) { - const container = scrollRef.current - const child = container.children[currentIndex] as HTMLElement + const child = scrollRef.current.children[idx] as HTMLElement if (child) { - container.scrollTo({ left: child.offsetLeft, behavior: 'smooth' }) + scrollRef.current.scrollTo({ left: child.offsetLeft, behavior: 'smooth' }) } } - }, [currentIndex]) + } const handleScroll = (e: React.UIEvent) => { const container = e.currentTarget @@ -66,7 +66,7 @@ export default function ProductImageGallery({ images, fallback, alt = 'Product I