I have tried solutions related with Javascript and React using state, but I can't do it with Hooks. I want to add 3 seconds delay for each element that I'm rendering on array.map
import React, { useState } from 'react';
const DelayMapHooks = () => {
const [array, setArray] = useState([1, 2, 3])
return (
<div>
{
array.map((elem, key) => {
// ADD DELAY HERE FOR EACH ELEMENT
return( <div>Number: {elem}</div> )
})
}
</div>
);
};
export default DelayMapHooks;
I have tried adding an await/async immediately after the map, using await delay(3000) with the function
const delay = ms => {return(new Promise(res => setTimeout(res, ms)))}
But it doesn't work, showing the error: Objects are not valid as a React child (found: [object Promise]). Appreciated any help.