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

@kubb/plugin-swr

Generates typed SWR hooks from your OpenAPI spec, so data fetching stays in sync with the API.

swrreacthooksdata-fetchingcodegenopenapi
Stijn Van Hulle

Stijn Van Hulle

@stijnvanhulle

Downloads
45.9K/ mo
Stars
8
Bundle size
344.5 kB
Updated
39m ago

Generate typed SWR hooks from OpenAPI.

  • Each hook calls a generated Axios or Fetch client.

Installation

bun add -d @kubb/plugin-swr

Or run kubb add plugin-swr to install the version the Kubb registry pins and add pluginSwr() to kubb.config.ts.

Dependencies

  • Add pluginTs and an Axios or Fetch client plugin.
  • Generated hooks require SWR v2 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 { pluginSwr } from '@kubb/plugin-swr'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  plugins: [
    pluginTs(),
    pluginFetch(),
    pluginSwr(),
  ],
})

See also