I am trying to create an alert component in React.JS which would receive one array as props and then loop through all the elements inside and display them in the alert component.
I do not know how to restart the loop when the array map ends.
This is my code:
useEffect(() => {
props.messages.map((item, index) => {
setTimeout(() => {
setMessage(item);
}, 5000*index)
});
},[]);
I want to run the loop continuously until the user closes the notification alert.
My guess is to wrap the map inside a while / do while in order to run it until the user closes the notification bar. I am having trouble restarting the loop once the map of the array gets to the last element.