I am trying to change a text (it begins automatically when the screen appears) at every time interval in react, but the problem is that, the time given isn't respected, and the text is changing at a random time interval. This is a part of my code:
const names = [
'tony', 'elias', 'fadi'
]
const [newName, setnewName] = useState(0);
useEffect(() => {
for (const [index, value] of names.entries()) {
setTimeout(() => { shuffle(value) }, 5000);
}
})
const shuffle = (value) => {
setnewName(value);
}
And thank you!