Created
June 28, 2021 12:18
-
-
Save ooooak/22a6ba45e031b049fafff8d9828955f0 to your computer and use it in GitHub Desktop.
This file contains 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
import { unAuthed } from '@utils/http'; | |
import axios, { CancelTokenSource } from 'axios' | |
import { useState } from 'react'; | |
export function AxiosAbortTest(){ | |
let source: CancelTokenSource | undefined; | |
async function requestResource(){ | |
if (source){ | |
source.cancel('Operation canceled due to new request.'); | |
} | |
source = axios.CancelToken.source(); | |
unAuthed('/', {cancelToken: source.token}).catch(e => { | |
console.log(e); | |
}) | |
} | |
return ( | |
<a href="" onClick={async (e) =>{ | |
e.preventDefault(); | |
await requestResource() | |
}}>Send Request</a> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment