2021年5月4日星期二

Create new instance of abortController() after fetch cancelled in React

I'm using AbortController to cancel a fetch request in my React app for a registration form. It's set to abort after 2 secs on button click if the email used to register is already in my database. The initial abort works as expected but is stuck there if I try to press the register button again to try a different email.

I've read that you have to call a new instance each click and to set new AbortController() as state to get it to work.

I've tried to set it in state but with no luck.

How do I call a new instance each time so that I'm able to rerun the fetch request after each button click?

https://stackoverflow.com/questions/67394278/create-new-instance-of-abortcontroller-after-fetch-cancelled-in-react May 05, 2021 at 10:05AM

没有评论:

发表评论