Let us learn how to deal with the “Can’t perform a React state update on an unmounted component” warning
Let us take a look at an implementation o...
For further actions, you may consider blocking this person and/or reporting abuse
Great post, didn't knew about the AbortController, just learned cool stuff, thanks!
Just one small correction, I think that in the cleanup function of the AbortController example, you want to call abortController.abort().
Additionally, you can check the status of the abort signal before doing any state-changing assignments.
Though that can be done, it will never return true since whenever the signal will be aborted, the code would enter the catch block because of the exception thrown.
Thanks, that was a typo and I have updated it.
yes, I was thinking the same.
Great post man, that way you declared a variable inside useEffect to know when the component is mounted or not, was genius 💥
Thank you. Glad it was helpful! Yeah the variable to know if the component is mounted or not was something that I had come across when doing a related task and it was super helpful to do it that way.
One of the few advantages that axios has over fetch is that it has Cancel support including on IE, so if you have to support IE it might be good to use a library to polyfill in cancellation?
I would rather use a polyfill than use axios, but that is again a personal preference. If there are other features that axios provides (specific to the use case), I might go for it. You could just use the first approach of a boolean flag as well.
But if it is just cancellation support for IE, you could take a look at the example repo
Install:
Add the following:
There are other features like request and response interceptors that axios provides by the way.
As I mentioned, if there are other features that you are using, go for it. But most people are not using those features, thus the recommendation.
This is cool. I use axios and its cancel token. This was helpful !! :)
Thank you! Glad it was helpful. I prefer libraries only when there is a compelling need to use them. :)
Nice post! Was clear and easy to understand.
Thank you!
Glad it helped. Thank you!
Thank you! fetch has become my go-to recently over any libraries.