Warning: setState(...): Can only update a mounted or mounting component. This usually means you c...

报这个警告,十有八九是没有成功removeEventListener所致,我就是这样的。这里引用stackoverflow上原文的链接。

大致意思就是bind会new一个新的函数出来,所以addEventListener也好,removeEventListener都别使用bind去传listener的参,我们在constructor里面bind就好了:

constructor(props) {
  super(props);
  this.onScroll = this.onScroll.bind(this);
}

也是挺坑的,在此记录一下。

你可能感兴趣的:(Warning: setState(...): Can only update a mounted or mounting component. This usually means you c...)