Why use useeffect of state in react? code example
Example 1: useeffect react
useEffect(() => {
// code goes here
return () => {
// cleanup code codes here
};
},[]);
Example 2: useeffect react
useEffect(() => {
window.addEventListener('mousemove', () => {});
// returned function will be called on component unmount
return () => {
window.removeEventListener('mousemove', () => {})
}
}, [])