In the React documentation for hooks they say:
\"This also allows you to handle out-of-order responses with a local variable inside the effect\"
//all imports function mufunc(){ useEffect(()=>{ const a = addEventListner('mouse' , console.log('mouse moves') ) //it prints when //mouse moves return ()=>{ removeEventListner(a) //whenever the component removes it will executes } } ,[]) }