Created
October 12, 2018 09:32
-
-
Save smashingpat/5518872de40667516e17111a94a2dc1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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