Skip to content
Officialv5.1.5MITkubb >=5.0.0node >=22

@kubb/plugin-react-query

Generates typed TanStack Query hooks for React from your OpenAPI spec, so reads and writes call your API through useQuery, useMutation, and useInfiniteQuery without hand-written boilerplate.

react-querytanstack-queryreacthooksdata-fetchingcodegenopenapi
Stijn Van Hulle

Stijn Van Hulle

@stijnvanhulle

Downloads
419.8K/ mo
Stars
8
Bundle size
556.8 kB
Updated
4d ago

Generate TanStack Query helpers from OpenAPI.

  • Option factories and cache keys by default.
  • React hooks when hooks: true.

Installation

bun add -d @kubb/plugin-react-query

Dependencies

  • Add pluginTs and an Axios or Fetch client plugin.
  • Generated output requires @tanstack/react-query v5 or higher.
  • Configure validation on the client plugin.

Example

kubb.config.ts
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 }),
  ],
})

See also