react-component / m-pull-to-refresh

React Mobile Pull To Refresh
http://react-component.github.io/m-pull-to-refresh/
164 stars 61 forks source link

建议clearTimeout 一下 this._timer #5

Open zuoge85 opened 7 years ago

zuoge85 commented 7 years ago

建议clearTimeout 一下 this._timer

我在使用的时候发现犹豫没有clearTimeout this._timer,造成

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 PullToRefresh component.

zuoge85 commented 7 years ago

我使用如下代码解决


RPullToRefresh.prototype.componentWillUnmount = function () {
  this.destroy(this.props.getScrollContainer() || this.containerRef);
  if(this._timer){
    clearTimeout(this._timer);
  }
  if(this._initTimer){
    clearTimeout(this._initTimer);
  }
};

RPullToRefresh.prototype.componentDidMount = function () {
  this._initTimer = setTimeout(() => {
    this.init(this.props.getScrollContainer() || this.containerRef);
    this.triggerPullToRefresh();
    delete this._initTimer;
  });
};