Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 警告和异常整理 #5

Open
BingoStyle opened this issue Jan 30, 2019 · 2 comments
Open

React 警告和异常整理 #5

BingoStyle opened this issue Jan 30, 2019 · 2 comments
Labels

Comments

@BingoStyle
Copy link
Owner

BingoStyle commented Jan 30, 2019

  1. 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.
    解决思路:通过修饰器Decorator一劳永逸 但对于Decorator的支持?那就改为使用一个函数来解决
    值得关注点:setState hook inside useEffect can cause unavoidable warning Can't perform a React state update facebook/react#14369
@anddero
Copy link

anddero commented May 5, 2020

Mentioned in #14369 comment that it might be fixed in 16.9.

I am using 16.13.0 and this issue still appears if a setState is called from a useEffect of an unmounted component.

@anddero
Copy link

anddero commented May 5, 2020

The solutions proposed in #14369 seem to be workarounds to only avoid the warning from being logged, but pollute the code-base significantly, if there is a large project where hundreds or even thousands of similar methods are used. It would not make sense to add that much boiler-plate to just avoid an occasional warning.

The workarounds do not seem to be solutions to the actual problem where methods continue execution after their owner component has been unmounted. IMO, there isn't much of a difference between checking a boolean for deciding whether or not to call setState, and letting React detect that setState is called for an unmounted component. Other than producing the warning.

Could there be a more elegant solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants