cuitianze / React-ReactNative-Redux_NOTEBOOK

React&ReactNative&Redux 不完全手册
2 stars 0 forks source link

[React]ExceptionsManager.js:76 Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the undefined component. #1

Open cuitianze opened 8 years ago

cuitianze commented 8 years ago

ExceptionsManager.js:76 Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the undefined component.

  async getStockSnapshot() {
    ...
      this.requestAgain = setTimeout(()=>{
        this.getStockSnapshot();
       }, this.state.request_frequency);
    ...
  }
  componentWillUnmount() {
    console.log('WillUnmount');
    this.requestAgain && clearTimeout(this.requestAgain);
  }

this 指向当前组件 this.requestAgain 是setTimeout 函数生成的 唯一标识符

cuitianze commented 8 years ago

这个问题不仅仅在于React,还需要深入探索下setTimeout所在函数重复执行所导致的n遍重复, 何时去clear这些定时函数很重要,不仅仅是在componentWillUnmount的时候。