Plugin
plugins: [pluginSwr()]Officialv5.6.0kubb >=5.8.3node >=22.22
SWR
@kubb/plugin-swr
Generates typed SWR hooks from your OpenAPI spec, so data fetching stays in sync with the API.
kubb add plugin-swr
swrreacthooksdata-fetchingcodegenopenapi
- Downloads35.9K/ monthnpm, last 30 days
- GitHub stars9kubb-labs/plugins
- Unpacked size426.1kBv5.6.0 on npm
- Latest release1h agov5.6.0 · Oct 27, 2026
The SWR plugin generates a useSWR hook for each query and a useSWRMutation hook for each mutation.
The plugin ships no HTTP client. Each hook calls a function generated by a client plugin.
Installation
bun add -d @kubb/plugin-swrpnpm add -D @kubb/plugin-swrnpm install --save-dev @kubb/plugin-swryarn add -D @kubb/plugin-swrOr run kubb add plugin-swr to install the version the Kubb registry pins and add pluginSwr() to kubb.config.ts.
Setup
- Add
@kubb/plugin-ts, orpluginZod({ inferred: 'codec' })for codec types, and a client plugin:@kubb/plugin-fetch,@kubb/plugin-axios, or@kubb/plugin-client. Leavesdkunset on the client plugin. - Install
swr2.2 or a later v2 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.queryandmutationset which HTTP methods become queries (GET) and mutations (POST,PUT,PATCH,DELETE). They also set where SWR is imported from (swrandswr/mutation). Set either tofalseto skip those hooks.
The plugin does not generate useSWRInfinite hooks.
See Options for every option and its default.
Example
The config below generates useSWR and useSWRMutation hooks that call the Fetch client.
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(),
],
})Dependencies
Extensions that must be in the same config as SWR.
Optional dependencies
Extensions SWR works with when they are in the config.