API Documentation / @pinia/colada / DefineQueryOptionsTagged
Interface: DefineQueryOptionsTagged<TData, TError, TDataInitial>
Tagged version of DefineQueryOptions that includes a key with data type information.
Extends
DefineQueryOptions
<TData
,TError
,TDataInitial
>
Type Parameters
TData
TData
= unknown
TError
TError
= ErrorDefault
TDataInitial
TDataInitial
extends TData
| undefined
= undefined
Properties
autoRefetch?
optional autoRefetch: boolean;
Whether to enable auto refresh by default.
Default
false
Inherited from
DefineQueryOptions.autoRefetch
delay?
optional delay: number | false;
Delay in milliseconds to wait before letting the asyncStatus
become 'loading'
. Set to false
or 0 to disable. Requires the PiniaColadaDelay plugin.
Default
200
Inherited from
DefineQueryOptions.delay
enabled?
optional enabled: boolean;
Whether the query should be enabled or not. If false
, the query will not be executed until refetch()
or refresh()
is called. If it becomes true
, the query will be refreshed.
Inherited from
DefineQueryOptions.enabled
gcTime?
optional gcTime: number | false;
Time in ms after which, once the data is no longer being used, it will be garbage collected to free resources. Set to false
to disable garbage collection.
Default
300_000 (5 minutes)
Inherited from
DefineQueryOptions.gcTime
initialData?
optional initialData: _IsMaybeRefOrGetter<() => TDataInitial> extends true ? undefined | _UnwrapMaybeRefOrGetter<() => TDataInitial> : undefined | () => TDataInitial & () => TDataInitial;
The data which is initially set to the query while the query is loading for the first time. Note: unlike with placeholderData, setting the initial data changes the state of the query (it will be set to success
).
See
Inherited from
DefineQueryOptions.initialData
key
key: EntryKeyTagged<TData, TError, TDataInitial>;
The key used to identify the query. Array of primitives without reactive values or a reactive array or getter. It should be treaded as an array of dependencies of your queries, e.g. if you use the route.params.id
property, it should also be part of the key:
import { useRoute } from 'vue-router'
import { useQuery } from '@pinia/colada'
const route = useRoute()
const { data } = useQuery({
// pass a getter function (or computed, ref, etc.) to ensure reactivity
key: () => ['user', route.params.id],
query: () => fetchUser(route.params.id),
})
Overrides
DefineQueryOptions.key
placeholderData?
optional placeholderData: (_IsMaybeRefOrGetter<NonNullable<NoInfer<TDataInitial> | NoInfer<TData> | (<T extends TData>(previousData: T | undefined) => NoInfer<TDataInitial> | NoInfer<TData> | undefined) | undefined>> extends true ? _UnwrapMaybeRefOrGetter<...> | ... 2 more ... | undefined : NoInfer<TDataInitial> | ... 2 more ... | undefined)...;
A placeholder data that is initially shown while the query is loading for the first time. This will also show the status
as success
until the query finishes loading (no matter the outcome of the query). Note: unlike with initialData, the placeholder does not change the cache state.
See
Inherited from
DefineQueryOptions.placeholderData
query()
query: (context) => Promise<TData>;
The function that will be called to fetch the data. It must be async.
Parameters
context
UseQueryFnContext
Returns
Promise
<TData
>
Inherited from
DefineQueryOptions.query
refetchOnMount?
optional refetchOnMount: RefetchOnControl;
Whether to refetch the query when the component is mounted.
Default
true
Inherited from
DefineQueryOptions.refetchOnMount
refetchOnReconnect?
optional refetchOnReconnect: RefetchOnControl;
Whether to refetch the query when the network reconnects.
Default
true
Inherited from
DefineQueryOptions.refetchOnReconnect
refetchOnWindowFocus?
optional refetchOnWindowFocus: RefetchOnControl;
Whether to refetch the query when the window regains focus.
Default
true
Inherited from
DefineQueryOptions.refetchOnWindowFocus
retry?
optional retry:
| number
| RetryOptions
| (failureCount, error) => boolean;
Options for the retries of this query added by @pinia/colada-plugin-retry
.
Inherited from
DefineQueryOptions.retry
staleTime?
optional staleTime: number;
Time in ms after which the data is considered stale and will be refreshed on next read.
Default
5000 (5 seconds)
Inherited from
DefineQueryOptions.staleTime