Every time the request finishes loading I need to wait 10 seconds and fetch the data. So far I use 2 useEffects one to verify if the data is ready and the other to loop the counter until it gets to 0. I was wondering if there is a better way.
useEffect(() => {
if (!loading) {
timer = setInterval(() => setCounter(value => value - 1), 1000)
}
}, [loading])
useEffect(() => {
if (counter === 0) {
clearInterval(timer)
refetch()
setCounter(10)
}
}, [counter, refetch])