写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.
查了一下发现是Unmount时依然继续setState导致报错,总结一下发现有2种解决方案。
1.在componentWillUnmount时重新定义setState:
componentWillUnmount() {
this.setState = (status, callback) => {
return;
};
}
2.大概思路:在资源没加载完成时使用Loading,使其不能离开此页面。