An experienced software developer with a strong background in developing award-winning web and mobile applications for diverse clients with 6+ years of industry experience.
Thanks for the suggestion! This AbortController solution makes more explicit the cancel operation. Anyways, I don't use it very often because of the low browser support. Maybe, I should start using it shipping a polyfill for older browsers 🤔.
An experienced software developer with a strong background in developing award-winning web and mobile applications for diverse clients with 6+ years of industry experience.
how can i use this hook for submitting a form? it gives me an error because it's calling inside the submitHandler function. Or it's better just to write an asynchronous function for this?
This hook cannot work for mutation requests, like form submissions, because it starts the fetch request as soon as the component is mounted. If you need to handle form submissions you should write a "classic" async handler.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice article but you should look into AbortController for that
subscribed
part as this would also cancel the actual request if it is ongoing:Thanks for the suggestion! This
AbortController
solution makes more explicit the cancel operation. Anyways, I don't use it very often because of the low browser support. Maybe, I should start using it shipping a polyfill for older browsers 🤔.If you are worried about browser support, axios offers a similar API on top of XHR or go the polyfill way as you have said.
how can i use this hook for submitting a form? it gives me an error because it's calling inside the submitHandler function. Or it's better just to write an asynchronous function for this?
This hook cannot work for mutation requests, like form submissions, because it starts the fetch request as soon as the component is mounted. If you need to handle form submissions you should write a "classic" async handler.