Warning: 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 a useEffect cleanup function.
problem
pro-antd 开发模式下,login 页面登陆之后报错
Warning: 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 a useEffect cleanup function.
reason
异常信息:组件销毁了,但是react还在set state
网络请求回来之后使用setState,如果组件被销毁的话就会报这个错误
翻到issue:
https://github.com/ant-design/ant-design-pro/issues/10283
https://github.com/ant-design/ant-design-pro/issues/9470
solution
// src/pages/user/Login/index.tsx handleSubmit 方法里加一个定时器,异步执行
// hack: 解决 Warning: Can't perform a React state update on an unmounted component.
setTimeout(() => {
history.push(redirect || '/');
}, 0);