From 5b22c11e0d7058b0a1d327f90a13404fc9fdfb23 Mon Sep 17 00:00:00 2001 From: Landon Gavin Date: Wed, 18 Oct 2023 14:24:30 -0400 Subject: [PATCH] deps(react query): update to react query 5 --- examples/react-app/package.json | 4 +- examples/react-app/src/App.tsx | 36 +- examples/react-app/src/main.tsx | 5 +- examples/react-app/src/queryClient.tsx | 3 + package.json | 4 +- pnpm-lock.yaml | 1167 +++++++++++++----------- src/createUseMutation.ts | 75 +- src/createUseQuery.ts | 317 ++++--- 8 files changed, 880 insertions(+), 731 deletions(-) create mode 100644 examples/react-app/src/queryClient.tsx diff --git a/examples/react-app/package.json b/examples/react-app/package.json index 561bf9d..ae7e861 100644 --- a/examples/react-app/package.json +++ b/examples/react-app/package.json @@ -6,14 +6,14 @@ "scripts": { "dev": "run-p dev:mock dev:client", "dev:client": "vite --clearScreen=false", - "dev:mock": "prism mock ./petstore.yaml", + "dev:mock": "prism mock ./petstore.yaml --dynamic", "build": "tsc && vite build", "preview": "vite preview", "generate:api": "node ../../dist/src/cli.js -i ./petstore.yaml -c axios --exportSchemas=true --postfixServices=Client --request ./request.ts", "test:generated": "tsc ./openapi/queries/index.ts --noEmit --target esnext --moduleResolution node" }, "dependencies": { - "@tanstack/react-query": "^4.29.7", + "@tanstack/react-query": "^5.0.0", "axios": "^1.4.0", "form-data": "~4.0.0", "react": "^18.2.0", diff --git a/examples/react-app/src/App.tsx b/examples/react-app/src/App.tsx index 6b602fe..207c618 100644 --- a/examples/react-app/src/App.tsx +++ b/examples/react-app/src/App.tsx @@ -2,20 +2,28 @@ import "./App.css"; import { useDefaultClientAddPet, useDefaultClientFindPets, + useDefaultClientFindPetsKey, } from "../openapi/queries"; +import { useState } from 'react'; +import { queryClient } from './queryClient'; function App() { - const { data } = useDefaultClientFindPets( - { tags: [], limit: 10 }, - [], - { - onError: (error) => { - console.error(error); - }, - } + + const [tags, _setTags] = useState([]); + const [limit, _setLimit] = useState(10); + + const { data, error, refetch } = useDefaultClientFindPets( + { tags, limit }, ); - const mutation = useDefaultClientAddPet(); + const { mutate: addPet } = useDefaultClientAddPet(); + + if (error) return ( +
+

Failed to fetch pets

+ +
+ ); return (
@@ -27,12 +35,18 @@ function App() {