简体   繁体   中英

Building a react app but getting an error message that I can't locate: Warning: Can't perform a React state update on an unmounted component

Im getting the below error and struggling to find the source of the problem. Based on the error I see in the console, should I investigate the lines; Toolbar.js:15? is there console suggesting the error is there?

Also, what is the general origin of this type of issues?

在此处输入图像描述

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM