Replies: 1 comment
-
The easiest way would be to add a wrapper composable in your application that sets the defaults, and then utilize that composable rather than the native export. Here's an example: import type { IConfig } from 'swrv'
import useSWRV from 'swrv'
import type { AxiosResponse, AxiosError } from 'axios'
import type { IKey, fetcherFn } from 'swrv/dist/types'
import { computed } from 'vue'
export default function useSwrvRequest<Data = unknown, Error = { message: string }>(key: IKey, fn?: fetcherFn<AxiosResponse<Data>>, config?: IConfig) {
const { data: response, error, isValidating, mutate } = useSWRV<
AxiosResponse<Data>,
AxiosError<Error>
>(key, fn, {
// Add default options
dedupingInterval: 100,
// Allow overriding the default config options when calling the composable
...config,
})
const data = computed((): Data | undefined => {
return response.value?.data
})
return {
data,
response,
error,
isValidating,
mutate,
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to set default global options? For instance I would like to increase the dedupe interval from the default 2000 ms, Is there a way to do this without having to update every single useSWRV function call?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions