I am trying to cycle loop through an array of items, when the end of the array has been reached it should go back to the first item in the array, I have the following code it's not behaving the way I would like it to, and the dom doesn't update and my approach is not working!
const items = ["item-1", "item-2", "item-2", "item-3"];
var count = useRef(0);
useEffect(() => {
setInterval(() => {
if (count.current <= items.length) count.current = count.current++;
else count.current = 0;
}, 3000);
});
return (
<>
<p> {items[count]} </p>
</>
)