# MystBin ! - Caraousel.tsx import { useState, useEffect } from 'react' import {Right, Left} from './icons' const Caraousel = ({ images }: { images: Array}) => { const [current, setCurrent] = useState(0) const [touchStartX, setTouchStartX] = useState(0) const [touchEndX, setTouchEndX] = useState(0) const previousSlide = () => { setCurrent(prevIndex => (prevIndex - 1 + images.length) % images.length) } const nextSlide = () => { setCurrent(prevIndex => (prevIndex + 1) % images.length) } const handleTouchEnd = (e: React.TouchEvent) => { const touchDiff = touchEndX - touchStartX if(touchDiff > 50) { previousSlide() } else if (touchDiff < -50) { nextSlide() } setTouchStartX(0) setTouchEndX(0) } useEffect(() => { const interval = setInterval(() => { setCurrent(prevIndex => (prevIndex + 1) % images.length) },5000) return () => clearInterval(interval) },[images.length]) return (
setTouchStartX(e.touches[0].clientX)} onTouchMove={e => setTouchEndX(e.touches[0].clientX)} onTouchEnd={handleTouchEnd}>
    {images.map((image, index) => (
  • {`Caraousel
  • ))}
) } export default Caraousel