QueryFactory
For usage after instantiation, see Query.
ChimericQueryFactory
Section titled “ChimericQueryFactory”Creates a ChimericQuery backed by TanStack Query’s cache.
import { ChimericQueryFactory } from '@chimeric/react-query';import { QueryClient, queryOptions } from '@tanstack/react-query';
const queryClient = new QueryClient();
const getUser = ChimericQueryFactory<{ id: string }, User>({ queryClient, getQueryOptions: (params) => queryOptions({ queryKey: ['user', params.id], queryFn: () => fetch(`/api/users/${params.id}`).then((r) => r.json()), }),});
// Without paramsconst getAllTodos = ChimericQueryFactory<void, Todo[]>({ queryClient, getQueryOptions: () => queryOptions({ queryKey: ['todos'], queryFn: () => fetch('/api/todos').then((r) => r.json()), }),});Config
Section titled “Config”| Property | Type | Description |
|---|---|---|
queryClient | QueryClient | TanStack Query client instance |
getQueryOptions | (params) => ReturnType<typeof queryOptions> | Returns TanStack query options for given params |
Suspense
Section titled “Suspense”In addition to the standard .useHook(), the TanStack Query integration provides .useSuspenseHook() for use with React Suspense:
const { data } = getUser.useSuspenseHook({ id: userId });// data is guaranteed non-undefinedSee Suspense for details.
IdiomaticQueryFactory
Section titled “IdiomaticQueryFactory”Same config as ChimericQueryFactory. Returns only the idiomatic path — a callable async function with .prefetch(). No hooks.
ReactiveQueryFactory
Section titled “ReactiveQueryFactory”Same config without queryClient — uses the QueryClient from React context. Returns only the reactive path (.useHook(), .useSuspenseHook(), .usePrefetchHook()).