Skip to content

API Documentation / @pinia/colada / UseQueryReturn

Interface: UseQueryReturn<TData, TError, TDataInitial>

Return type of useQuery().

Extends

  • UseQueryEntryExtensions<TData, TError, TDataInitial>

Extended by

Type Parameters

TData

TData = unknown

TError

TError = ErrorDefault

TDataInitial

TDataInitial extends TData | undefined = undefined

Properties

asyncStatus

ts
asyncStatus: ComputedRef<AsyncStatus>;

Status of the query. Becomes 'loading' while the query is being fetched, is 'idle' otherwise.


data

ts
data: ShallowRef<TData | TDataInitial>;

The last successful data resolved by the query. Alias for state.value.data.

See

state


dataUpdatedAt?

ts
optional dataUpdatedAt: ShallowRef<number>;

Timestamp of when data was last successfully fetched. TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.dataUpdatedAt

error

ts
error: ShallowRef<TError | null>;

The error rejected by the query. Alias for state.value.error.

See

state


errorUpdatedAt?

ts
optional errorUpdatedAt: ShallowRef<number>;

Timestamp of when an error last occurred. TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.errorUpdatedAt

fetchStatus?

ts
optional fetchStatus: ComputedRef<FetchStatus>;

TanStack Query compatible fetch status. Maps to: 'fetching' when loading, 'idle' otherwise. Note: 'paused' is not currently supported.

Inherited from

ts
UseQueryEntryExtensions.fetchStatus

isDelaying

ts
isDelaying: ShallowRef<boolean>;

Returns whether the query is currently delaying its asyncStatus from becoming 'loading'. Requires the PiniaColadaDelay plugin.

Inherited from

ts
UseQueryEntryExtensions.isDelaying

isError?

ts
optional isError: ComputedRef<boolean>;

Whether the query status is 'error'. TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.isError

isFetched?

ts
optional isFetched: ShallowRef<boolean>;

Whether the query has fetched at least once. TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.isFetched

isFetchedAfterMount?

ts
optional isFetchedAfterMount: ShallowRef<boolean>;

Whether the query has fetched after component mount. TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.isFetchedAfterMount

isFetching?

ts
optional isFetching: ComputedRef<boolean>;

Whether the query is currently fetching (asyncStatus === 'loading'). TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.isFetching

isLoading

ts
isLoading: ShallowRef<boolean>;

Returns whether the request is currently fetching data. Alias for asyncStatus.value === 'loading'


isLoadingError?

ts
optional isLoadingError: ComputedRef<boolean>;

Whether the query errored on initial load (never had data). TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.isLoadingError

isPending

ts
isPending: ComputedRef<boolean>;

Returns whether the request is still pending its first call. Alias for status.value === 'pending'


isPlaceholderData

ts
isPlaceholderData: ComputedRef<boolean>;

Returns whether the data is the placeholderData.


isRefetchError?

ts
optional isRefetchError: ComputedRef<boolean>;

Whether the query errored on refetch (had data before). TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.isRefetchError

isRefetching?

ts
optional isRefetching: ComputedRef<boolean>;

Whether the query is refetching (fetching but not initial load). TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.isRefetching

isStale?

ts
optional isStale: ComputedRef<boolean>;

Whether the query data is stale. TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.isStale

isSuccess?

ts
optional isSuccess: ComputedRef<boolean>;

Whether the query status is 'success'. TanStack Query compatible property.

Inherited from

ts
UseQueryEntryExtensions.isSuccess

refetch()

ts
refetch: (throwOnError?) => Promise<DataState<TData, TError, TDataInitial>>;

Ignores fresh data and triggers a new fetch

Parameters

throwOnError?

boolean

whether to throw an error if the fetch fails. Defaults to false

Returns

Promise<DataState<TData, TError, TDataInitial>>

a promise that resolves when the fetch is done


refresh()

ts
refresh: (throwOnError?) => Promise<DataState<TData, TError, TDataInitial>>;

Ensures the current data is fresh. If the data is stale, refetch, if not return as is.

Parameters

throwOnError?

boolean

whether to throw an error if the refresh fails. Defaults to false

Returns

Promise<DataState<TData, TError, TDataInitial>>

a promise that resolves when the refresh is done


state

ts
state: ComputedRef<DataState<TData, TError, TDataInitial>>;

The state of the query. Contains its data, error, and status.


status

ts
status: ShallowRef<DataStateStatus>;

The status of the query. Alias for state.value.status.

See

Released under the MIT License.