Usually this happens when you try to update the state on a component that is no longer mounted, which is pretty common for asynchronous operations such as timers or requests.
What some like to do is to set a flag on the componentDidMount()
method and unset that flag on the componentWillUnmount()
method, a flag commonly named this.mounted
. With this, you can verify the state of your component before you call the setState()
and make sure it is only called when the component is still mounted.
Let me know if you have any questions.
Hope this was helpful.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.