I'm using setInterval
in useEffect
. When use not actively using tab, I't requesting like forever. It causing some memory issue. I have to, fetch data in every 3000ms
, also stop it when user is not using this tab actively. How can I do such a thing?
I tried to use document.visibiltyState
and I couldn't worked it.
My code:
useEffect(() => {
try {
const interval = setInterval(() => {
getTransactionGroupStats()
getTransactionGroups()
}, 3000)
getBinanceBalanceStats()
return () => {
clearInterval(interval)
}
} catch (error) {
console.error(error)
}
}, [])