Problem Statement
Explain the difference between effects with cleanup and without cleanup.
Explanation
Effects without cleanup run once and don’t need cleanup, like fetching data. Effects with cleanup return a function that removes subscriptions or listeners when the component unmounts.
Code Solution
SolutionRead Only
useEffect(() => {
const timer = setInterval(() => console.log('tick'), 1000);
return () => clearInterval(timer);
}, []);