如何解决“可以在未填充的组件上执行React状态更新”。反应天然
错误警告:无法在未填充组件上执行React状态更新。这是一个无操作,但表示您的应用程序中的内存泄漏。要修复,请在使用效率清理功能中取消所有订阅和异步任务。
useEffect(() => {
userIsRegister();
if (sendMessage === '') {
getAllMessage();
}
}, [sendMessage, isFocused]);
ERROR 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.
useEffect(() => {
userIsRegister();
if (sendMessage === '') {
getAllMessage();
}
}, [sendMessage, isFocused]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如错误指示的那样,当组件已经卸下时,正在更新反应。在组件被卸下后,似乎返回了一些异步任务。
如上所述,您可以找到这些并使用使用效果的清理方法。另一种方法可以是向USEREF变量维护组件已安装的状态并仅在仍安装组件时才执行使用效应主体。
As error indicates, the react is being updated while component is already unmounted. It seems that some async task is returned after component is unmounted.
As mentioned in error, you can find out those and used the useEffect's clean-up method. Another way can be to useRef variable to maintain the component mounted state and execute the useEffect body only if component is still mounted.