为了解决React内存泄露的问题,从网上找到了方法解决,但是相关代码在ESlint中报错比较多,自己尝试着解决这些报错,但是一直没能成功。
求助一下各位大佬。
类修饰器的代码
export function injectUnount (target){
const next = target.prototype.componentWillUnmount
target.prototype.componentWillUnmount = function () {
if (next) next.call(this, ...arguments);
this.unmount = true
}
let setState = target.prototype.setState
target.prototype.setState = function () {
if ( this.unmount ) return ;
setState.call(this, ...arguments)
}
}
这样的看到你代码报错的eslint 的规则
修改如下: