相关疑难解决方法(0)

无法在已卸载的组件上执行React状态更新

问题

我正在React中编写一个应用程序,无法避免出现一个超级常见的陷阱,该陷阱正在调用setState(...)after componentWillUnmount(...)

我非常仔细地查看了我的代码,并尝试放置一些保护子句,但是问题仍然存在,并且我仍在观察警告。

因此,我有两个问题:

  1. 我如何从堆栈跟踪中找出哪个特定的组件和事件处理程序或生命周期挂钩负责违反规则?
  2. 好吧,如何解决问题本身,因为我的代码在编写时就考虑到了这种陷阱,并且已经在试图防止这种情况发生,但是某些底层组件仍在生成警告。

浏览器控制台

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 the componentWillUnmount
method.
    in TextLayerInternal (created by Context.Consumer)
    in TextLayer (created by PageInternal) index.js:1446
d/console[e]
index.js:1446
warningWithoutStack
react-dom.development.js:520
warnAboutUpdateOnUnmounted
react-dom.development.js:18238
scheduleWork
react-dom.development.js:19684
enqueueSetState
react-dom.development.js:12936
./node_modules/react/cjs/react.development.js/Component.prototype.setState
react.development.js:356
_callee$
TextLayer.js:97
tryCatch
runtime.js:63
invoke
runtime.js:282
defineIteratorMethods/</prototype[method]
runtime.js:116
asyncGeneratorStep …
Run Code Online (Sandbox Code Playgroud)

javascript setstate typescript lodash reactjs

28
推荐指数
11
解决办法
3万
查看次数

标签 统计

javascript ×1

lodash ×1

reactjs ×1

setstate ×1

typescript ×1