700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Warning: Can‘t perform a React state update on an unmounted component. This is a no-op but it indic

Warning: Can‘t perform a React state update on an unmounted component. This is a no-op but it indic

时间:2021-11-11 06:29:52

相关推荐

Warning: Can‘t perform a React state update on an unmounted component. This is a no-op  but it indic

问题描述:

报错信息: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.报错截图:

原因分析:

场景描述:React项目中,在页面加载中(未加载完成时)进行点击操作,报出。根据错误提示,无法对已经卸载的组件进行状态更新,这会导致内存泄漏。分析错误原因是,在做事件、定时器、网络请求等时,该事件没有完成时跳转到新的页面

解决方法:

取消事件

window.removeEventListener('事件类型',事件)

取消定时器

clearTimeout(定时器)

取消网络请求

这里主要是恢复网络请求的默认操作,比如更新数据恢复为默认值

return ()=>{ 操作1。。。 }

后续继续更新。。。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。