本页还没有译文
本页 79 段还没译成Español,下面显示的是英文原文。QueryCollectionConfig
还没翻译译自英文(tanstack.com)本页 79 段都还没译
Defined in: packages/query-db-collection/src/query.ts:108
Configuration options for creating a Query Collection
Extends
BaseCollectionConfig<T,TKey,TSchema,QueryCollectionUtils<T,TKey, [TSchema] extends [never] ?T:InferSchemaInput<TSchema>,TError>>
Type Parameters
T
T extends object = object
The explicit type of items stored in the collection
TQueryFn
TQueryFn extends (context) => any = (context) => any
The queryFn type
TError
TError = unknown
The type of errors that can occur during queries
TQueryKey
TQueryKey extends QueryKey = QueryKey
The type of the query key
TKey
TKey extends string | number = string | number
The type of the item keys
TSchema
TSchema extends StandardSchemaV1 = never
The schema type for validation
TQueryData
TQueryData = Awaited<ReturnType<TQueryFn>>
Properties
enabled?
optional enabled: Enabled<TQueryData, TError, TQueryData, TQueryKey>;Defined in: packages/query-db-collection/src/query.ts:147
Whether the query should automatically run (default: true)
gcTime?
optional gcTime: number;Defined in: packages/query-db-collection/src/query.ts:182
Time in milliseconds after which the collection will be garbage collected when it has no active subscribers. Defaults to 5 minutes (300000ms). Sync started without subscribers gets a minimum 50ms grace period. Pending preloads retain the collection until they settle. Preloading ready data refreshes the retention period. A non-positive or non-finite value disables automatic garbage collection.
Overrides
BaseCollectionConfig.gcTimeinitialData?
optional initialData: TQueryData | InitialDataFunction<TQueryData>;Defined in: packages/query-db-collection/src/query.ts:222
Data used to initialize the TanStack Query cache for an eager collection. The value has the original Query response shape and is projected through the collection's select option before rows are materialized.
initialDataUpdatedAt?
optional initialDataUpdatedAt: number | () => number | undefined;Defined in: packages/query-db-collection/src/query.ts:230
The timestamp TanStack Query uses to determine initialData freshness.
meta?
optional meta: Record<string, unknown>;Defined in: packages/query-db-collection/src/query.ts:259
Metadata to pass to the query. Available in queryFn via context.meta
Example
// Using meta for error context
queryFn: async (context) => {
try {
return await api.getTodos(userId)
} catch (error) {
// Use meta for better error messages
throw new Error(
context.meta?.errorMessage || 'Failed to load todos'
)
}
},
meta: {
errorMessage: `Failed to load todos for user ${userId}`
}networkMode?
optional networkMode: NetworkMode;Defined in: packages/query-db-collection/src/query.ts:210
persistedGcTime?
optional persistedGcTime: number;Defined in: packages/query-db-collection/src/query.ts:237
queryClient
queryClient: QueryClient;Defined in: packages/query-db-collection/src/query.ts:143
The TanStack Query client instance
queryFn
queryFn: TQueryFn extends (context) => any[] | Promise<any[]> ? (context) => T[] | Promise<T[]> : TQueryFn;Defined in: packages/query-db-collection/src/query.ts:132
Function that fetches data from the server. Must return the complete collection state
queryKey
queryKey: TQueryKey | TQueryKeyBuilder<TQueryKey>;Defined in: packages/query-db-collection/src/query.ts:130
The query key used by TanStack Query to identify this query
refetchInterval?
optional refetchInterval: number | false | (query) => number | false | undefined;Defined in: packages/query-db-collection/src/query.ts:154
refetchOnMount?
optional refetchOnMount: boolean | "always" | (query) => boolean | "always";Defined in: packages/query-db-collection/src/query.ts:203
refetchOnReconnect?
optional refetchOnReconnect: boolean | "always" | (query) => boolean | "always";Defined in: packages/query-db-collection/src/query.ts:196
refetchOnWindowFocus?
optional refetchOnWindowFocus: boolean | "always" | (query) => boolean | "always";Defined in: packages/query-db-collection/src/query.ts:189
retry?
optional retry: RetryValue<TError>;Defined in: packages/query-db-collection/src/query.ts:161
retryDelay?
optional retryDelay: RetryDelayValue<TError>;Defined in: packages/query-db-collection/src/query.ts:168
select()?
optional select: (data) => T[];Defined in: packages/query-db-collection/src/query.ts:141
Extracts the row array TanStack DB materializes from the Query response. The Query cache keeps the original response shape.
Parameters
data
TQueryData
Returns
T[]
staleTime?
optional staleTime: StaleTimeFunction<TQueryData, TError, TQueryData, TQueryKey>;Defined in: packages/query-db-collection/src/query.ts:175