I try to change background-image using setInterval which is compileable, but the problem is, it only change once.
here is my code ;
const [currentImage, setCurrentImage] = useState<string>("/a.jpg");
useEffect(() => {
const intervalId = setInterval(() => {
if (currentImage === "/a.jpg") {
setCurrentImage("/b.jg");
} else if (currentImage === "/b.jpeg") {
setCurrentImage("/c.jpg");
} else {
setCurrentImage("/a.jpg");
}
}, 6000);
return () => clearInterval(intervalId);
}, []);
how to correctly wrote setInterval in nextjs and make it return to starting image?