picostitch
crafting (and) JavaScript
#web

Cancel a fetch request using AbortController

Finally I learned how to abort a fetch, see the post React useEffect and fetch API by @Jaime.

As easy as this:

const controller = new AbortController();        
// we pass in a `signal` to `fetch` so that we can cancel the requests
fetch('http://example.com', { signal: controller.signal });
controller.abort();

Thanks Jaime!