An effect's cleanup function is the function returned by useEffect. React calls it before re-running the effect and when the component unmounts, to cancel a subscription, a timer or a request. The dependencies must list all the reactive values used in the effect.
Example
useEffect(() => {
const id = setInterval(tick, 1000);
return () => clearInterval(id);
}, []);