Set TimeOut to React Function

前端 未结 2 800
时光说笑
时光说笑 2021-01-21 20:34

I have the following object list:

mediaList[
 {id:1, url:\"www.example.com/image1\", adType:\"image/jpeg\"},
 {id:2, url:\"www.example.com/image2\", adType:\"ima         


        
2条回答
  •  清歌不尽
    2021-01-21 21:08

    Don't forget to clear the timeout to prevent memory leaks:

      componentDidMount() {
        this.timeout = setTimeout(() => {
         ...
        }, 300);
      }
    
      componentWillUnmount() {
        clearTimeout(this.timeout);
      }
    

提交回复
热议问题