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): add option for choosing shallowRef or ref #2251

Merged
merged 2 commits into from Sep 25, 2022
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
10 changes: 8 additions & 2 deletions packages/integrations/useAxios/index.ts
Expand Up @@ -92,6 +92,12 @@ export interface UseAxiosOptions {
*
*/
immediate?: boolean
/**
* Use shallowRef.
*
* @default true
*/
shallow?: boolean
}
type OverallUseAxiosReturn<T, D> = StrictUseAxiosReturn<T, D> | EasyUseAxiosReturn<T, D>

Expand All @@ -112,7 +118,7 @@ export function useAxios<T = any, D = any>(...args: any[]): OverallUseAxiosRetur
const argsPlaceholder = isString(url) ? 1 : 0
let defaultConfig: AxiosRequestConfig<D> = {}
let instance: AxiosInstance = axios
let options: UseAxiosOptions = { immediate: !!argsPlaceholder }
let options: UseAxiosOptions = { immediate: !!argsPlaceholder, shallow: true }

const isAxiosInstance = (val: any) => !!val?.request

Expand All @@ -139,7 +145,7 @@ export function useAxios<T = any, D = any>(...args: any[]): OverallUseAxiosRetur
options = args[args.length - 1]

const response = shallowRef<AxiosResponse<T>>()
const data = shallowRef<T>()
const data = options.shallow ? shallowRef<T>() : ref<T>()
const isFinished = ref(false)
const isLoading = ref(false)
const isAborted = ref(false)
Expand Down