Skip to content

Query

A ChimericQuery represents a cached read operation. Once instantiated via a React Query or RTK Query factory, usage is identical regardless of the backing library.

Call the query as an async function:

// With params
const user = await getUser({ id: '123' });
// Without params
const todos = await getAllTodos();
// With chimeric options
const user = await getUser({ id: '123' }, { options: { forceRefetch: true } });
// With native library options
const user = await getUser({ id: '123' }, { nativeOptions: { staleTime: 0 } });

Idiomatic options:

OptionTypeDescription
options.forceRefetchbooleanBypass cache staleness and force a fresh fetch
nativeOptionslibrary-specificPassed directly to the underlying query library

Populate the cache without returning the result. Useful for warming the cache ahead of navigation.

await getUser.prefetch({ id: '123' });
// Without params
await getAllTodos.prefetch();

Use .useHook() inside a React component:

function UserProfile({ userId }: { userId: string }) {
const { data, isPending, isError, error, refetch, native } = getUser.useHook(
{ id: userId },
{ options: { enabled: !!userId } },
);
if (isPending) return <div>Loading...</div>;
if (isError) return <div>Error: {error?.message}</div>;
return <div>{data?.name}</div>;
}

Return value:

PropertyTypeDescription
dataTResult | undefinedQuery result
isPendingbooleanInitial loading state
isIdlebooleanNo query has been made
isSuccessbooleanQuery succeeded
isErrorbooleanQuery errored
errorTError | nullError object
refetch() => Promise<TResult>Manually trigger a refetch
nativelibrary-specificFull result from the underlying query library

Reactive options:

OptionTypeDescription
options.enabledbooleanConditionally enable the query (default: true)
nativeOptionslibrary-specificPassed directly to the underlying query library

Prefetch data during render, before the subscribing component mounts:

getUser.usePrefetchHook({ id: nextUserId });

See also: Suspense for useSuspenseHook.