component willumount hook code example
Example 1: useeffect umnount
useEffect(() => {
return () => {
console.log("cleaned up");
};
}, []);
Example 2: componentwillunmount hooks
useEffect(() => {
window.addEventListener('mousemove', () => {});
// returned function will be called on component unmount
return () => {
window.removeEventListener('mousemove', () => {})
}
}, [])