Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(useAxios): support abortPrevious option #3735

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/integrations/useAxios/index.ts
Original file line number Diff line number Diff line change
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