I’m trying to make a random slide show using react hooks and set interval. How can I make a transition/ animation between the images?
thank you!
const imgArray = [img1, img2,img3,img4]
const [slideImg, setSlideImg] = useState(imgArray[utilService.getRandIntInclusive(0, imgArray.length - 1)])
useEffect(() => {
const intervalId = setInterval(() => {
setSlideImg(imgArray[utilService.getRandIntInclusive(0, imgArray.length - 1)])
}, 3000)
return function cleanup() {
clearInterval(intervalId)
}
})
return (
<section className='filter flex'>
<img src={slideImg} alt="" ></img>
</section >)
}