Client state · OpenAPI
TanStack Query bindings for each operation.
Adds caching and revalidation on top of the generated operations. Pair it with a client target rather than using it alone.
What it emits
Query and mutation hooksQuery options factoriesQuery key helpers
Options
Options this generator adds on top of its base set. Set them under generator: in the target.
| Option | Description | Values | Default |
|---|---|---|---|
envelope | Wrap successful responses in a fixed shape. Set `dataKey`, and optionally `metaKey`, `staticFields`, and `contextFields` for path and timestamp. | object | unset (no envelope) |
hooks | Emit the `useX` hooks themselves. | true | false | false |
options | Emit the standalone query and mutation options factories. | true | false | false |
suspense | Also emit `useSuspenseX` variants. | true | false | false |
operations | Per-operation overrides keyed by operation id. Each accepts `hooks`, `options`, `suspense`, and `infinite` — where `infinite` needs an explicit `parameter` and `initialPageParam`, because Kontract never guesses pagination policy. | object | unset |
Example
type: react-query-hooksgeneratesEach operation produces a query-options factory, a skippable variant, and the hook. Enabling suspense adds the suspense hook; mutations get an options factory and hook of their own.
targets:
- name: web-query
output: ./apps/web/src/api/query
generator:
type: react-query-hooks
zod: true
suspense: true// One operation, getProducts, produces:
export function getProductsQueryOptions(/* … */);
export function getProductsSkippableQueryOptions(/* … */);
export function useGetProducts(/* … */);
export function useSuspenseGetProducts(/* … */);
// And for a mutation, createProduct:
export function createProductMutationOptions(/* … */);
export function useCreateProduct(/* … */);