1- import { useState } from 'react' ;
1+ import { useState , useEffect } from 'react' ;
22import { products , ProductType } from '@/constants/ProductsData' ;
33import { Carousel } from 'react-responsive-carousel' ;
44import 'react-responsive-carousel/lib/styles/carousel.min.css' ;
@@ -20,6 +20,14 @@ const ProductCard = ({ product }: { product: ProductType }) => {
2020 const hasMultipleImages = imageUrls . length > 1 ;
2121 const [ currentImage , setCurrentImage ] = useState ( 0 ) ;
2222
23+ useEffect ( ( ) => {
24+ if ( ! hasMultipleImages ) return ;
25+ const interval = setInterval ( ( ) => {
26+ setCurrentImage ( ( prev ) => ( prev === imageUrls . length - 1 ? 0 : prev + 1 ) ) ;
27+ } , 3000 ) ;
28+ return ( ) => clearInterval ( interval ) ;
29+ } , [ hasMultipleImages , imageUrls . length ] ) ;
30+
2331 return (
2432 < div className = "grid grid-cols-1 md:grid-cols-2 gap-8 border-b dark:border-gray-700 pb-10" >
2533 { /* Product Image Carousel with custom hover controls */ }
@@ -30,10 +38,10 @@ const ProductCard = ({ product }: { product: ProductType }) => {
3038 showArrows = { false }
3139 showThumbs = { false }
3240 showStatus = { false }
33- showIndicators = { true }
34- infiniteLoop
35- useKeyboardArrows
36- swipeable
41+ showIndicators = { hasMultipleImages }
42+ infiniteLoop = { hasMultipleImages }
43+ useKeyboardArrows = { hasMultipleImages }
44+ swipeable = { hasMultipleImages }
3745 >
3846 { imageUrls . map ( ( img , idx ) => (
3947 < div key = { idx } >
0 commit comments