-
Notifications
You must be signed in to change notification settings - Fork 558
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
[Hooks] Abortable useEffect #137
Comments
Shouldn't |
Well As for
We are basically wrapping |
You probably wouldn't want |
nice idea |
I wrote this small library that does basically this a while ago. https://github.com/Flufd/use-current-effect |
Hi, thanks for your suggestion. RFCs should be submitted as pull requests, not issues. I will close this issue but feel free to resubmit in the PR format. |
RFC is now opened in #202. We should continue further discussion in there. |
When ever we use effect with a state update inside an async callback (or after an
await
) we probably want to check that we are not trying to update an unmounted component or worse, we are in a race condition and updating the state with the wrong data.With hooks, this is fairly simple to achieve using a boolean and a closure:
But doing that in each effect, every time we are dealing with a state update in an async operation can become tedious.
I played around and created an "abortable" effect, this effect is just a wrapper over
useEffect
and its providing astatus
indicator so the consumer can check if the effect was "cleaned":And the usage:
I wish that
useEffect
would provide this information out of the box instead of us writing it in "user land".The text was updated successfully, but these errors were encountered: