3 ms·
Sure there is. Set the interval on mount, clear it on unmount: useEffect(() => { const interval = setInterval(() => { // whatever }, 1000)
by robertoandred 5y ago
Sure there is. Set the interval on mount, clear it on unmount:
useEffect(() => {
const interval = setInterval(() => {
// whatever
}, 1000)
return () => {
clearInterval(interval);
}
}, [])