報這個警告,十有八九是沒有成功removeEventListener所致,我就是這樣的。這里引用stackoverflow上原文的鏈接。
大致意思就是bind會new一個新的函數出來,所以addEventListener也好,removeEventListener都別使用bind去傳listener的參,我們在constructor里面bind就好了:
constructor(props) {
super(props);
this.onScroll = this.onScroll.bind(this);
}
也是挺坑的,在此記錄一下。