plugins: [pluginReactQuery()]React Query
@kubb/plugin-react-query
Generates typed TanStack Query helpers for React from your OpenAPI spec: queryOptions and mutationOptions factories with their cache keys. Set hooks to also get useQuery and useMutation hooks, plus useInfiniteQuery when infinite is set.
- Downloads400.4K/ monthnpm, last 30 days
- GitHub stars8kubb-labs/plugins
- Unpacked size612.7kBv5.3.3 on npm
- Latest release9h agov5.3.3 · Oct 13, 2026
The React Query plugin generates TanStack Query helpers for React from your OpenAPI spec. By default you get queryOptions and mutationOptions factories with their query and mutation keys. Set hooks: true to also get useQuery and useMutation hooks.
The plugin ships no HTTP client. Each helper calls a function generated by a client plugin.
Installation
bun add -d @kubb/plugin-react-querypnpm add -D @kubb/plugin-react-querynpm install --save-dev @kubb/plugin-react-queryyarn add -D @kubb/plugin-react-queryOr run kubb add plugin-react-query to install the version the Kubb registry pins and add pluginReactQuery() to kubb.config.ts.
Setup
- Add
@kubb/plugin-tsand a client plugin:@kubb/plugin-fetchor@kubb/plugin-axios. Leavesdkunset on the client plugin. - Install
@tanstack/react-query5.82 or a later v5 release in the app that uses the generated code. - Configure validation on the client plugin, not here.
Options worth knowing
clientpicksfetchoraxioswhen both client plugins are registered. A single client is detected automatically.hooksadds theuse*hooks on top of the option factories.suspense: {}addsuseSuspenseQueryhooks. It needshooks: true.infiniteaddsuseInfiniteQueryhooks for pagination. It needshooks: trueand covers the operations that take the query parameter named ininfinite.queryParam, which defaults to'id'.queryandmutationset which HTTP methods become queries (GET) and mutations (POST,PUT,PATCH,DELETE). They also set where the TanStack Query runtime is imported from. Set either tofalseto skip those helpers.customOptions: { importPath }routes every hook through your own function that returns extra options. It needshooks: true. Kubb creates a starter file atimportPath, resolved from the generated hooks folder, when none exists and the path stays inside the plugin's output folder.
See Options for every option and its default.
Example
The config below generates useQuery and useMutation hooks that call the Fetch client.
import { defineConfig } from 'kubb/config'
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' },
plugins: [
pluginTs(),
pluginFetch(),
pluginReactQuery({ hooks: true }),
],
})Dependencies
Extensions that must be in the same config as React Query.