Plugin
plugins: [pluginReactQuery()]Officialv5.11.0kubb >=5.19.0node >=22.22
OpenAPI to React Query generator
@kubb/plugin-react-query
Generates typed TanStack Query helpers for React from your OpenAPI spec: queryOptions and mutationOptions factories with cache keys, plus optional hooks.
kubb add plugin-react-query
react-querytanstack-queryreacthooksdata-fetchingcodegenopenapi
- Downloads591.0K/ monthnpm, last 30 days
- GitHub stars12kubb-labs/plugins
- Unpacked size662.9kBv5.11.0 on npm
- Latest release1d agov5.11.0 · Nov 18, 2026
The React Query plugin generates TanStack Query queryOptions and mutationOptions factories with cache keys from your OpenAPI spec, plus optional hooks.
hooks: trueaddsuseQueryanduseMutationhooks, with suspense and infinite variants on request.- The plugin ships no HTTP client. Each helper calls a function from your client plugin.
Installation
kubb add plugin-react-querybun add -d @kubb/plugin-react-querypnpm add -D @kubb/plugin-react-querynpm install --save-dev @kubb/plugin-react-queryyarn add -D @kubb/plugin-react-querykubb add installs the version the Kubb registry pins and adds pluginReactQuery() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.
Setup
- Add
@kubb/plugin-ts, orpluginZod({ inferred: 'codec' })withzodv4 in the app. - Add one client plugin:
@kubb/plugin-fetch,@kubb/plugin-axios,@kubb/plugin-ky, or@kubb/plugin-client. Leavesdkunset on it. - Install
@tanstack/react-query5.82 or a later v5 release in the app. - Set the base URL, auth, and validation on the client plugin. With
@kubb/plugin-client, your client module owns them.
Options worth knowing
| Option | What it does |
|---|---|
client | Picks 'fetch', 'axios', 'ky', or 'client' when several client plugins are registered. |
hooks | Adds the use* hooks. infinite, suspense, and customOptions need it. |
query, mutation | Which HTTP methods become queries and mutations. false skips them. |
infinite | Adds infinite queries to operations with the infinite.queryParam parameter, 'id' by default. |
suspense | {} adds useSuspenseQuery hooks. |
customOptions | Routes every hook through your function for shared options. |
Example
This config generates hooks that call the Fetch client.
kubb.config.ts
import { defineConfig } from 'kubb/config'
import { adapterOas } from '@kubb/adapter-oas'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginFetch } from '@kubb/plugin-fetch'
import { pluginReactQuery } from '@kubb/plugin-react-query'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
adapter: adapterOas({ integerType: 'number' }),
plugins: [
pluginTs(),
pluginFetch(),
pluginReactQuery({ hooks: true }),
],
})See Options for every option. Next, call operations.
Dependencies
No extension dependencies.
Optional dependencies
Extensions React Query works with when they are in the config.
