Skip to content
IC Reactor

QueryResult

Defined in: react/src/types.ts:306

Result from createQuery

Includes useQuery hook that:

  • Supports enabled option for conditional fetching
  • Data may be undefined during loading
  • Uses regular useQuery with manual loading state handling

TQueryFnData

The raw data type

TSelected = TQueryFnData

The type after select transformation

TError = Error

The error type

fetch: () => Promise<TSelected>

Defined in: react/src/types.ts:233

Fetch data in loader (uses ensureQueryData for cache-first)

Promise<TSelected>

BaseQueryResult.fetch


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.

Promise<void>

// In a route hover handler
button.addEventListener("mouseenter", () => userQuery.prefetch())

BaseQueryResult.prefetch


invalidate: () => Promise<void>

Defined in: react/src/types.ts:248

Invalidate the cache (refetches if query is active)

Promise<void>

BaseQueryResult.invalidate


getQueryKey: () => readonly unknown[]

Defined in: react/src/types.ts:251

Get query key (for advanced React Query usage)

readonly unknown[]

BaseQueryResult.getQueryKey


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.

(): TSelected | undefined

TSelected | undefined

<TFinal>(select): TFinal | undefined

TFinal

(data) => TFinal

TFinal | undefined

TFinal

Type returned after optional select transformation

select

Optional select function to transform cached data further

Cached data with select applied, or undefined if not in cache

// Just get the cached data
const user = userQuery.getCacheData()
// With additional select transformation
const name = userQuery.getCacheData((user) => user.name)

BaseQueryResult.getCacheData


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.

TQueryFnData | ((old) => TQueryFnData | undefined)

TQueryFnData | undefined

// Optimistic update before a mutation
userQuery.setData({ id: "1", name: "Alice" })
// Functional update
counterQuery.setData((prev) => (prev ?? 0) + 1)

BaseQueryResult.setData


useQuery: UseQueryWithSelect<TQueryFnData, TSelected, TError>

Defined in: react/src/types.ts:312

React hook for components - supports chained select and enabled option