What is the expected return of `useEffect` used for?

前端 未结 4 1332
被撕碎了的回忆
被撕碎了的回忆 2021-02-15 13:35

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\"

4条回答
  •  被撕碎了的回忆
    2021-02-15 14:28

    //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
        }
      } ,[])
    }
    

提交回复
热议问题