[{"data":1,"prerenderedAt":642},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-react-query":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":641,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-react-query\u002Findex.md",{},"React Query",{"type":8,"value":9,"toc":632},"minimark",[10,23,43,48,148,178,182,233,237,363,367,370,619],[11,12,13,14,18,19,22],"p",{},"The React Query plugin generates TanStack Query ",[15,16,17],"code",{},"queryOptions"," and ",[15,20,21],{},"mutationOptions"," factories with cache keys from your OpenAPI spec, plus optional hooks.",[24,25,26,40],"ul",{},[27,28,29,32,33,18,36,39],"li",{},[15,30,31],{},"hooks: true"," adds ",[15,34,35],{},"useQuery",[15,37,38],{},"useMutation"," hooks, with suspense and infinite variants on request.",[27,41,42],{},"The plugin ships no HTTP client. Each helper calls a function from your client plugin.",[44,45,47],"h2",{"id":46},"installation","Installation",[49,50,52,75,95,113,131],"code-group",{"sync":51},"install",[53,54,59],"pre",{"language":55,"filename":56,"code":57,"class":58},"shell","kubb","kubb add plugin-react-query","highlights",[15,60,62],{"class":61},"language-shell",[63,64,67,71],"span",{"class":65,"style":66},"line","display: inline",[63,68,70],{"style":69},"color:#6f42c1;--hls-dark:#b392f0","kubb ",[63,72,74],{"style":73},"color:#24292e;--hls-dark:#e1e4e8","add plugin-react-query",[53,76,79],{"language":55,"filename":77,"code":78,"class":58},"bun","bun add -d @kubb\u002Fplugin-react-query",[15,80,81],{"class":61},[63,82,83,86,89,92],{"class":65,"style":66},[63,84,85],{"style":69},"bun ",[63,87,88],{"style":73},"add -d ",[63,90,91],{"style":73},"@",[63,93,94],{"style":73},"kubb\u002Fplugin-react-query",[53,96,99],{"language":55,"filename":97,"code":98,"class":58},"pnpm","pnpm add -D @kubb\u002Fplugin-react-query",[15,100,101],{"class":61},[63,102,103,106,109,111],{"class":65,"style":66},[63,104,105],{"style":69},"pnpm ",[63,107,108],{"style":73},"add -D ",[63,110,91],{"style":73},[63,112,94],{"style":73},[53,114,117],{"language":55,"filename":115,"code":116,"class":58},"npm","npm install --save-dev @kubb\u002Fplugin-react-query",[15,118,119],{"class":61},[63,120,121,124,127,129],{"class":65,"style":66},[63,122,123],{"style":69},"npm ",[63,125,126],{"style":73},"install --save-dev ",[63,128,91],{"style":73},[63,130,94],{"style":73},[53,132,135],{"language":55,"filename":133,"code":134,"class":58},"yarn","yarn add -D @kubb\u002Fplugin-react-query",[15,136,137],{"class":61},[63,138,139,142,144,146],{"class":65,"style":66},[63,140,141],{"style":69},"yarn ",[63,143,108],{"style":73},[63,145,91],{"style":73},[63,147,94],{"style":73},[11,149,150,153,154,159,160,163,164,167,168,170,171,177],{},[15,151,152],{},"kubb add"," installs the version the ",[155,156,158],"a",{"href":157},"\u002Fregistry","Kubb registry"," pins and adds ",[15,161,162],{},"pluginReactQuery()"," to ",[15,165,166],{},"kubb.config.ts",". It needs a ",[15,169,166],{},", so run ",[155,172,174],{"href":173},"\u002Fdocs\u002F5.x\u002Freference\u002Fcommands\u002Finit",[15,175,176],{},"kubb init"," first in a new project.",[44,179,181],{"id":180},"setup","Setup",[24,183,184,199,220,227],{},[27,185,186,187,190,191,194,195,198],{},"Add ",[15,188,189],{},"@kubb\u002Fplugin-ts",", or ",[15,192,193],{},"pluginZod({ inferred: 'codec' })"," with ",[15,196,197],{},"zod"," v4 in the app.",[27,200,201,202,205,206,205,209,190,212,215,216,219],{},"Add one client plugin: ",[15,203,204],{},"@kubb\u002Fplugin-fetch",", ",[15,207,208],{},"@kubb\u002Fplugin-axios",[15,210,211],{},"@kubb\u002Fplugin-ky",[15,213,214],{},"@kubb\u002Fplugin-client",". Leave ",[15,217,218],{},"sdk"," unset on it.",[27,221,222,223,226],{},"Install ",[15,224,225],{},"@tanstack\u002Freact-query"," 5.82 or a later v5 release in the app.",[27,228,229,230,232],{},"Set the base URL, auth, and validation on the client plugin. With ",[15,231,214],{},", your client module owns them.",[44,234,236],{"id":235},"options-worth-knowing","Options worth knowing",[238,239,240,253],"table",{},[241,242,243],"thead",{},[244,245,246,250],"tr",{},[247,248,249],"th",{},"Option",[247,251,252],{},"What it does",[254,255,256,280,305,322,339,354],"tbody",{},[244,257,258,264],{},[259,260,261],"td",{},[15,262,263],{},"client",[259,265,266,267,205,270,205,273,190,276,279],{},"Picks ",[15,268,269],{},"'fetch'",[15,271,272],{},"'axios'",[15,274,275],{},"'ky'",[15,277,278],{},"'client'"," when several client plugins are registered.",[244,281,282,287],{},[259,283,284],{},[15,285,286],{},"hooks",[259,288,289,290,293,294,205,297,300,301,304],{},"Adds the ",[15,291,292],{},"use*"," hooks. ",[15,295,296],{},"infinite",[15,298,299],{},"suspense",", and ",[15,302,303],{},"customOptions"," need it.",[244,306,307,315],{},[259,308,309,205,312],{},[15,310,311],{},"query",[15,313,314],{},"mutation",[259,316,317,318,321],{},"Which HTTP methods become queries and mutations. ",[15,319,320],{},"false"," skips them.",[244,323,324,328],{},[259,325,326],{},[15,327,296],{},[259,329,330,331,334,335,338],{},"Adds infinite queries to operations with the ",[15,332,333],{},"infinite.queryParam"," parameter, ",[15,336,337],{},"'id'"," by default.",[244,340,341,345],{},[259,342,343],{},[15,344,299],{},[259,346,347,32,350,353],{},[15,348,349],{},"{}",[15,351,352],{},"useSuspenseQuery"," hooks.",[244,355,356,360],{},[259,357,358],{},[15,359,303],{},[259,361,362],{},"Routes every hook through your function for shared options.",[44,364,366],{"id":365},"example","Example",[11,368,369],{},"This config generates hooks that call the Fetch client.",[53,371,374],{"language":372,"filename":166,"code":373,"class":58},"typescript","import { defineConfig } from 'kubb\u002Fconfig'\nimport { adapterOas } from '@kubb\u002Fadapter-oas'\nimport { pluginTs } from '@kubb\u002Fplugin-ts'\nimport { pluginFetch } from '@kubb\u002Fplugin-fetch'\nimport { pluginReactQuery } from '@kubb\u002Fplugin-react-query'\n\nexport default defineConfig({\n  input: '.\u002FpetStore.yaml',\n  output: { path: '.\u002Fsrc\u002Fgen' },\n  adapter: adapterOas({ integerType: 'number' }),\n  plugins: [\n    pluginTs(),\n    pluginFetch(),\n    pluginReactQuery({ hooks: true }),\n  ],\n})",[15,375,377,400,401,400,417,400,433,400,449,400,465,400,467,400,481,400,498,400,522,400,550,400,562,400,575,400,586,400,606,400,615],{"class":376},"language-typescript",[63,378,379,383,387,390,393,396],{"class":65,"style":66},[63,380,382],{"style":381},"color:#d73a49;--hls-dark:#f97583","import ",[63,384,386],{"style":385},"color:#005cc5;--hls-dark:#79b8ff","{ ",[63,388,389],{"style":73},"defineConfig ",[63,391,392],{"style":385},"} ",[63,394,395],{"style":381},"from ",[63,397,399],{"style":398},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fconfig'","\n",[63,402,403,405,407,410,412,414],{"class":65,"style":66},[63,404,382],{"style":381},[63,406,386],{"style":385},[63,408,409],{"style":73},"adapterOas ",[63,411,392],{"style":385},[63,413,395],{"style":381},[63,415,416],{"style":398},"'@kubb\u002Fadapter-oas'",[63,418,419,421,423,426,428,430],{"class":65,"style":66},[63,420,382],{"style":381},[63,422,386],{"style":385},[63,424,425],{"style":73},"pluginTs ",[63,427,392],{"style":385},[63,429,395],{"style":381},[63,431,432],{"style":398},"'@kubb\u002Fplugin-ts'",[63,434,435,437,439,442,444,446],{"class":65,"style":66},[63,436,382],{"style":381},[63,438,386],{"style":385},[63,440,441],{"style":73},"pluginFetch ",[63,443,392],{"style":385},[63,445,395],{"style":381},[63,447,448],{"style":398},"'@kubb\u002Fplugin-fetch'",[63,450,451,453,455,458,460,462],{"class":65,"style":66},[63,452,382],{"style":381},[63,454,386],{"style":385},[63,456,457],{"style":73},"pluginReactQuery ",[63,459,392],{"style":385},[63,461,395],{"style":381},[63,463,464],{"style":398},"'@kubb\u002Fplugin-react-query'",[63,466],{"class":65,"style":66},[63,468,469,472,475,478],{"class":65,"style":66},[63,470,471],{"style":381},"export ",[63,473,474],{"style":381},"default ",[63,476,477],{"style":69},"defineConfig",[63,479,480],{"style":385},"({",[63,482,483,486,489,492,495],{"class":65,"style":66},[63,484,485],{"style":385},"  ",[63,487,488],{"style":385},"input",[63,490,491],{"style":381},": ",[63,493,494],{"style":398},"'.\u002FpetStore.yaml'",[63,496,497],{"style":381},",",[63,499,500,502,505,507,509,512,514,517,520],{"class":65,"style":66},[63,501,485],{"style":381},[63,503,504],{"style":385},"output",[63,506,491],{"style":381},[63,508,386],{"style":385},[63,510,511],{"style":385},"path",[63,513,491],{"style":381},[63,515,516],{"style":398},"'.\u002Fsrc\u002Fgen' ",[63,518,519],{"style":385},"}",[63,521,497],{"style":381},[63,523,524,526,529,531,534,537,540,542,545,548],{"class":65,"style":66},[63,525,485],{"style":381},[63,527,528],{"style":385},"adapter",[63,530,491],{"style":381},[63,532,533],{"style":69},"adapterOas",[63,535,536],{"style":385},"({ ",[63,538,539],{"style":385},"integerType",[63,541,491],{"style":381},[63,543,544],{"style":398},"'number' ",[63,546,547],{"style":385},"})",[63,549,497],{"style":381},[63,551,552,554,557,559],{"class":65,"style":66},[63,553,485],{"style":381},[63,555,556],{"style":385},"plugins",[63,558,491],{"style":381},[63,560,561],{"style":385},"[",[63,563,564,567,570,573],{"class":65,"style":66},[63,565,566],{"style":385},"    ",[63,568,569],{"style":69},"pluginTs",[63,571,572],{"style":385},"()",[63,574,497],{"style":381},[63,576,577,579,582,584],{"class":65,"style":66},[63,578,566],{"style":381},[63,580,581],{"style":69},"pluginFetch",[63,583,572],{"style":385},[63,585,497],{"style":381},[63,587,588,590,593,595,597,599,602,604],{"class":65,"style":66},[63,589,566],{"style":381},[63,591,592],{"style":69},"pluginReactQuery",[63,594,536],{"style":385},[63,596,286],{"style":385},[63,598,491],{"style":381},[63,600,601],{"style":385},"true ",[63,603,547],{"style":385},[63,605,497],{"style":381},[63,607,608,610,613],{"class":65,"style":66},[63,609,485],{"style":381},[63,611,612],{"style":385},"]",[63,614,497],{"style":381},[63,616,617],{"class":65,"style":66},[63,618,547],{"style":385},[11,620,621,622,626,627,631],{},"See ",[155,623,625],{"href":624},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-react-query\u002Foptions","Options"," for every option. Next, ",[155,628,630],{"href":629},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-react-query\u002Fguides\u002Fcalling-operations","call operations",".",{"title":633,"searchDepth":634,"depth":634,"links":635},"",5,[636,638,639,640],{"id":46,"depth":637,"text":47},2,{"id":180,"depth":637,"text":181},{"id":235,"depth":637,"text":236},{"id":365,"depth":637,"text":366},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-react-query",1795547697932]