Created
October 14, 2020 14:37
-
-
Save arnonate/1af165a6af57b5908150f7b1c4d91bfe 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
React.useEffect( () => { | |
const abortCtrl = new AbortController(); | |
fetch( | |
`some_url`, | |
{ | |
method: "get", | |
headers: new Headers( { | |
"Content-Type": "application/json", | |
"Accept": "application/json", | |
"Authorization": `Bearer ${some_token}`, | |
} ), | |
signal: abortCtrl.signal, | |
} | |
) | |
.then( response => response.json() ) | |
.then( response => { | |
// Do something with response | |
} ); | |
return () => abortCtrl.abort(); | |
}, [] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment