Skip to content

Commit

Permalink
deps(react query): update to react query 5
Browse files Browse the repository at this point in the history
  • Loading branch information
seriouslag committed Oct 18, 2023
1 parent b34afd2 commit f3e47e5
Show file tree
Hide file tree
Showing 8 changed files with 884 additions and 731 deletions.
4 changes: 2 additions & 2 deletions examples/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 25 additions & 11 deletions examples/react-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>([]);
const [limit, _setLimit] = useState<number>(10);

const { data, error, refetch } = useDefaultClientFindPets(
{ tags, limit },
);

const mutation = useDefaultClientAddPet();
const { mutate: addPet } = useDefaultClientAddPet();

if (error) return (
<div>
<p>Failed to fetch pets</p>
<button onClick={() => refetch()}>Retry</button>
</div>
);

return (
<div className="App">
Expand All @@ -27,12 +35,18 @@ function App() {
</ul>
<button
onClick={() => {
mutation.mutate(
addPet(
{
requestBody: { name: "Duggy" },
},
{
onSuccess: () => console.log("success"),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: [useDefaultClientFindPetsKey],
});
console.log("success")

},
onError: (error) => console.error(error),
}
);
Expand Down
5 changes: 2 additions & 3 deletions examples/react-app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'
import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query'
const queryClient = new QueryClient()

import { QueryClientProvider } from '@tanstack/react-query'
import { queryClient } from './queryClient'
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
Expand Down
3 changes: 3 additions & 0 deletions examples/react-app/src/queryClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { QueryClient } from '@tanstack/react-query';

export const queryClient = new QueryClient();
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
"license": "MIT",
"devDependencies": {
"@types/node": "^18.16.0",
"commander": "^10.0.1",
"commander": "^11.1.0",
"glob": "^10.2.5",
"openapi-typescript-codegen": "^0.24.0",
"typescript": "^5.0.4"
},
"peerDependencies": {
"commander": ">= 10 < 11",
"commander": ">= 11 < 12",
"glob": ">= 10",
"openapi-typescript-codegen": "^0.24.0",
"typescript": ">= 4.8.3"
Expand Down
Loading

0 comments on commit f3e47e5

Please sign in to comment.