首页 > 技术文章 > react添加和删除定时器的地方

javenlee 2017-12-05 14:32 原文

添加定时器
  componentDidMount() {
    this.timerID = setInterval(
      () => this.tick(),
      1000
    );
  }

 删除定时器

  componentWillUnmount() {
    clearInterval(this.timerID);
  }

  

 

推荐阅读