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, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
今天在开发的时候功能没有问题,但是控制台报这个错误,然后在网上搜了一下,解决了,在这里记录一下,以后方便看。
问题
解决方案
将生命周期componentDidMount修改为componentWillUnmount就可以了
原因:不能在组件销毁后设置state,防止出现内存泄漏的情况,
组件都被销毁了,就不能设置state了