Skip to content

API Documentation / @pinia/colada / UseInfiniteQueryOptions

Interface: UseInfiniteQueryOptions<TData, TError, TPageParam, TDataInitial>

Experimental

Options for useInfiniteQuery.

See https://github.com/posva/pinia-colada/issues/178

Extends

  • Omit<UseQueryOptions<UseInfiniteQueryData<TData, TPageParam>, TError, TDataInitial>, "query" | "key">

Type Parameters

TData

TData

TError

TError

TPageParam

TPageParam

TDataInitial

TDataInitial extends | UseInfiniteQueryData<TData, TPageParam> | undefined

Properties

autoRefetch?

ts
optional autoRefetch: number | boolean | <T>(state) => number | boolean;

Experimental

Whether to enable auto refresh by default.

Default

ts
false

Inherited from

ts
Omit.autoRefetch

delay?

ts
optional delay: number | false;

Experimental

Delay in milliseconds to wait before letting the asyncStatus become 'loading'. Set to false or 0 to disable. Requires the PiniaColadaDelay plugin.

Default

ts
200

Inherited from

UseQueryOptions.delay


enabled?

ts
optional enabled: MaybeRefOrGetter<boolean>;

Experimental

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

UseQueryOptionsGlobal.enabled


gcTime?

ts
optional gcTime: number | false;

Experimental

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

ts
300_000 (5 minutes)

Inherited from

ts
Omit.gcTime

getNextPageParam()

ts
getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) => NoInfer<TPageParam> | null | undefined;

Experimental

Function to get the next page parameter based on the last page and all pages fetched so far. If it returns undefined or null, it will consider there are no more pages to fetch.

Parameters

lastPage

NoInfer<TData>

allPages

NoInfer<TData>[]

lastPageParam

NoInfer<TPageParam>

allPageParams

NoInfer<TPageParam>[]

Returns

NoInfer<TPageParam> | null | undefined


getPreviousPageParam()?

ts
optional getPreviousPageParam: (firstPage, allPages, firstPageParam, allPageParams) => TPageParam | null | undefined;

Experimental

Function to get the previous page parameter based on the first page and all pages fetched so far. If it returns undefined or null, it will consider there are no more pages to fetch.

Parameters

firstPage

TData

allPages

TData[]

firstPageParam

TPageParam

allPageParams

TPageParam[]

Returns

TPageParam | null | undefined


initialData()?

ts
optional initialData: () => TDataInitial;

Experimental

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).

Returns

TDataInitial

See

placeholderData

Inherited from

ts
Omit.initialData

initialDataUpdatedAt?

ts
optional initialDataUpdatedAt: number | () => number;

Experimental

The timestamp (in milliseconds) when the initial data was last updated. This determines the staleness of the initialData. If not provided, defaults to Date.now() when initial data is set.

Default

Date.now() when initialData is used

Example

ts
// Using a static timestamp
useQuery({
  key: ['user'],
  query: () => fetchUser(),
  initialData: () => cachedUser,
  initialDataUpdatedAt: 1234567890000
})

// Using a function
useQuery({
  key: ['user'],
  query: () => fetchUser(),
  initialData: () => cachedUser,
  initialDataUpdatedAt: () => Number(localStorage.getItem('userTimestamp'))
})

Inherited from

ts
Omit.initialDataUpdatedAt

initialPageParam

ts
initialPageParam: TPageParam | () => TPageParam;

Experimental

Initial page parameter or function returning it. It's passed to the query


key

ts
key: MaybeRefOrGetter<EntryKey>;

Experimental


maxPages?

ts
optional maxPages: number;

Experimental

Maximum number of pages to keep in the cache. Old pages will be removed from the cache when new pages are added. If not set, all pages will be kept.


meta?

ts
optional meta: MaybeRefOrGetter<Record<string, unknown>>;

Experimental

Meta information associated with the query. Can be a raw object, a function returning the meta object, or a ref containing the meta object. The meta is resolved when the entry is created and stored in entry.meta.

Note: Meta is serialized during SSR, so it must be serializable (no functions, class instances, or circular references). You can also completely ignore it during SSR with a ternary: meta: import.meta.ev.SSR ? {} : actualMeta

Example

ts
// SSR-safe: simple serializable data
useQuery({
  key: ['user', id],
  query: () => fetchUser(id),
  meta: { errorMessage: true }
})

// Using a function to compute meta
useQuery({
  key: ['user', id],
  query: () => fetchUser(id),
  meta: () => ({ timestamp: Date.now() })
})

// Skipping meta during SSR
useQuery({
  key: ['user', id],
  query: () => fetchUser(id),
  meta: {
    onError: import.meta.env.SSR ? undefined : ((err) => console.log('error'))
  }
})

Inherited from

ts
Omit.meta

placeholderData?

ts
optional placeholderData: 
  | NoInfer<TDataInitial>
  | NoInfer<UseInfiniteQueryData<TData, TPageParam>>
  | <T>(previousData) => 
  | NoInfer<TDataInitial>
  | NoInfer<UseInfiniteQueryData<TData, TPageParam>>
  | undefined;

Experimental

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

initialData

Inherited from

ts
Omit.placeholderData

query()

ts
query: (context) => Promise<TData>;

Experimental

The function that will be called to fetch the data. It must be async.

Parameters

context

UseInfiniteQueryFnContext<UseInfiniteQueryData<unknown, TPageParam>, TError, TDataInitial, TPageParam>

Returns

Promise<TData>


refetchOnMount?

ts
optional refetchOnMount: MaybeRefOrGetter<RefetchOnControl>;

Experimental

Whether to refetch the query when the component is mounted.

Default

ts
true

Inherited from

UseQueryOptionsGlobal.refetchOnMount


refetchOnReconnect?

ts
optional refetchOnReconnect: MaybeRefOrGetter<RefetchOnControl>;

Experimental

Whether to refetch the query when the network reconnects.

Default

ts
true

Inherited from

UseQueryOptionsGlobal.refetchOnReconnect


refetchOnWindowFocus?

ts
optional refetchOnWindowFocus: MaybeRefOrGetter<RefetchOnControl>;

Experimental

Whether to refetch the query when the window regains focus.

Default

ts
true

Inherited from

UseQueryOptionsGlobal.refetchOnWindowFocus


retry?

ts
optional retry: 
  | number
  | RetryOptions
  | (failureCount, error) => boolean;

Experimental

Options for the retries of this query added by @pinia/colada-plugin-retry.

Inherited from

ts
Omit.retry

ssrCatchError?

ts
optional ssrCatchError: boolean;

Experimental

Whether to catch errors during SSR (onServerPrefetch) when the query fails.

Default

ts
false

Inherited from

UseQueryOptionsGlobal.ssrCatchError


staleTime?

ts
optional staleTime: number;

Experimental

Time in ms after which the data is considered stale and will be refreshed on next read.

Default

ts
5000 (5 seconds)

Inherited from

UseQueryOptionsGlobal.staleTime

Released under the MIT License.