I’m trying to iterate through an array of images stored in variables using the wait() function. I want say a 2 second iteration through each. I had it working with Math.floor(Math.random) but want to try just iterating through each one individually using wait.
const [imgSrc, setImgSrc] = useState(tb);
useEffect(() => {
const wait = (time) => new Promise((resolve) => setTimeout(resolve, time));
const interval = setInterval(() => {
const images = [tb3, tb];
for (let i = 0; i < images.length; i++) {
setImgSrc(images[i]);
wait(1000);
}
}, 2000);
return () => clearInterval(interval);
}, []);