Skip to content

Instantly share code, notes, and snippets.

@smashingpat
Created October 12, 2018 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smashingpat/5518872de40667516e17111a94a2dc1b to your computer and use it in GitHub Desktop.
Save smashingpat/5518872de40667516e17111a94a2dc1b to your computer and use it in GitHub Desktop.
// Create the controller that sends a signal if
// an abort is requested by the api
const abortController = new AbortController();
// create a fetch, and pass the signal from the controller to
// the fetch options
const request = fetch('http://my-awesome-site.com/api/awesome', {
signal: abortController.signal,
});
// abort the fetch from anywhere, like from user interaction on a button
// or a React Component dismounting
abortController.abort();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment