I have a Media.json file which has 6 media objects with (name, duration, fileType). I want to loop through them and want to show one single item at a time with dynamic duration according to media object duration property. i have tried this with setTimeout and SetInterval looping in and outside of them but still unable to do that. I am using react js with functional components. Help would be very appreciated. my example code.
const [mediaItem, setMediaItem] = useState({})
const items = [{ name: 'one' }, { name: 'two' }, { name: 'three' }];
const renderMedia = () => {
for (let i = 0; i < items.length; i++) {
setTimeout(() => {
setMediaItem(items[i]);
console.log(mediaItem);
}, 5000);
}
// return items[currentIndex].name;
};
Thanks