SuspenseQueryResult
Defined in: react/src/types.ts:327
Result from createSuspenseQuery
Includes useSuspenseQuery hook that:
- Requires wrapping in
boundary - Data is always defined (no undefined checks)
- Does NOT support
enabledoption
Extends
Section titled “Extends”BaseQueryResult<TQueryFnData,TSelected,TError>
Type Parameters
Section titled “Type Parameters”TQueryFnData
Section titled “TQueryFnData”TQueryFnData
The raw data type
TSelected
Section titled “TSelected”TSelected = TQueryFnData
The type after select transformation
TError
Section titled “TError”TError = Error
The error type
Properties
Section titled “Properties”fetch: () =>
Promise<TSelected>
Defined in: react/src/types.ts:233
Fetch data in loader (uses ensureQueryData for cache-first)
Returns
Section titled “Returns”Promise<TSelected>
Inherited from
Section titled “Inherited from”prefetch
Section titled “prefetch”prefetch: () =>
Promise<void>
Defined in: react/src/types.ts:245
Eagerly prefetch data into the cache without blocking. Useful for preloading data before navigating to a route.
Unlike fetch(), this returns a void promise so it can be fire-and-forget.
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”// In a route hover handlerbutton.addEventListener("mouseenter", () => userQuery.prefetch())Inherited from
Section titled “Inherited from”invalidate
Section titled “invalidate”invalidate: () =>
Promise<void>
Defined in: react/src/types.ts:248
Invalidate the cache (refetches if query is active)
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”getQueryKey
Section titled “getQueryKey”getQueryKey: () => readonly
unknown[]
Defined in: react/src/types.ts:251
Get query key (for advanced React Query usage)
Returns
Section titled “Returns”readonly unknown[]
Inherited from
Section titled “Inherited from”getCacheData
Section titled “getCacheData”getCacheData: {():
TSelected|undefined; <TFinal>(select):TFinal|undefined; }
Defined in: react/src/types.ts:268
Read data directly from cache without fetching. Returns undefined if data is not in cache.
Call Signature
Section titled “Call Signature”():
TSelected|undefined
Returns
Section titled “Returns”TSelected | undefined
Call Signature
Section titled “Call Signature”<
TFinal>(select):TFinal|undefined
Type Parameters
Section titled “Type Parameters”TFinal
Section titled “TFinal”TFinal
Parameters
Section titled “Parameters”select
Section titled “select”(data) => TFinal
Returns
Section titled “Returns”TFinal | undefined
Template
Section titled “Template”TFinal
Type returned after optional select transformation
select
Optional select function to transform cached data further
Returns
Section titled “Returns”Cached data with select applied, or undefined if not in cache
Example
Section titled “Example”// Just get the cached dataconst user = userQuery.getCacheData()
// With additional select transformationconst name = userQuery.getCacheData((user) => user.name)Inherited from
Section titled “Inherited from”setData
Section titled “setData”setData: (
updater) =>TQueryFnData|undefined
Defined in: react/src/types.ts:287
Write raw data directly into the cache (useful for optimistic updates). Accepts a new value or an updater function that receives the current cached raw data.
Note: The value is stored as raw (pre-select) data. Any active select
transformations are automatically re-applied by React Query on the next render.
Parameters
Section titled “Parameters”updater
Section titled “updater”TQueryFnData | ((old) => TQueryFnData | undefined)
Returns
Section titled “Returns”TQueryFnData | undefined
Example
Section titled “Example”// Optimistic update before a mutationuserQuery.setData({ id: "1", name: "Alice" })
// Functional updatecounterQuery.setData((prev) => (prev ?? 0) + 1)Inherited from
Section titled “Inherited from”useSuspenseQuery
Section titled “useSuspenseQuery”useSuspenseQuery:
UseSuspenseQueryWithSelect<TQueryFnData,TSelected,TError>
Defined in: react/src/types.ts:333
React hook for components - data is always defined (wrap in Suspense)