Using setInterval in React Component

前端 未结 3 1513
一生所求
一生所求 2020-12-06 13:18

I was reading the tutorial on the official react website. In the example about life cycle methods, under the componentDidMount method, a timerID is set to the setInterval fu

3条回答
  •  佛祖请我去吃肉
    2020-12-06 13:57

    In this react document it's written that

    We will tear down the timer in the componentWillUnmount() lifecycle method

    So, this.timerID will be used in componentWillUnmount() lifecycle method to stop timer.

提交回复
热议问题