React报错:Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix,

今天在开发时报了以下错误,记录一下

React报错:Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix,

我们不能在组件销毁后设置state,防止出现内存泄漏的情况

出现原因直接告诉你了,组件都被销毁了,还设置个锤子的state啊

解决方案:

利用生命周期钩子函数:componentWillUnmount

将报错的地方移入此钩子里进行处理

componentWillUnmount(){
//处理逻辑
}

上一篇:Linux 网络编程 入门-常用函数


下一篇:Linux网络编程学习路线