Skip to content

Commit

Permalink
feat(useAxios): support abortPrevious option (#3735)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
jahnli and antfu committed Feb 20, 2024
1 parent 5025e3a commit b94de90
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/integrations/useAxios/index.ts
Expand Up @@ -76,6 +76,13 @@ export interface UseAxiosOptions<T = any> {
*/
shallow?: boolean

/**
* Abort previous request when a new request is made.
*
* @default true
*/
abortPrevious?: boolean

/**
* Callback when error is caught.
*/
Expand Down Expand Up @@ -121,6 +128,7 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
const defaultOptions: UseAxiosOptions<T> = {
immediate: !!argsPlaceholder,
shallow: true,
abortPrevious: true,
}
let defaultConfig: AxiosRequestConfig<D> = {}
let instance: AxiosInstance = axios
Expand Down Expand Up @@ -218,7 +226,10 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
return promise
}
resetData()
abort()

if (options.abortPrevious)
abort()

loading(true)

executeCounter += 1
Expand Down

0 comments on commit b94de90

Please sign in to comment.