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

fix(useAxios): ignore undefined options #3662

Merged
merged 8 commits into from Jan 9, 2024
Merged

Conversation

geektheripper
Copy link
Contributor

@geektheripper geektheripper commented Dec 17, 2023

Description

When the options parameter is undefined, the code ignores it.

This facilitates writing code in the following manner: export const useFoobar = (opts?: UseAxiosOptions) => useAxios<Foobar>('/foobar', api, opts).

In terms of compatibility, since the code below performs a destructuring assignment on options, passing in undefined would lead to a crash. Therefore, there should not be widespread practical use cases for passing in undefined.

if (
(args.length === 2 + argsPlaceholder && !isAxiosInstance(args[1 + argsPlaceholder]))
|| args.length === 3 + argsPlaceholder
)
options = args[args.length - 1]
const {
initialData,
shallow,
onSuccess = noop,
onError = noop,
immediate,
resetOnExecute = false,
} = options

Copy link
Member

@Doctor-wu Doctor-wu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

packages/integrations/useAxios/index.ts Show resolved Hide resolved
Doctor-wu
Doctor-wu previously approved these changes Dec 31, 2023
@antfu antfu changed the title axios intergration: ignore undefined options fix(useAxios): ignore undefined options Jan 3, 2024
@antfu antfu added this pull request to the merge queue Jan 9, 2024
Merged via the queue into vueuse:main with commit 37eaea3 Jan 9, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants