-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathApp.tsx
73 lines (66 loc) · 1.98 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import "./App.css";
import {
useDefaultServiceAddPet,
useDefaultServiceFindPets,
useDefaultServiceFindPetsKey,
useDefaultServiceGetNotDefined,
useDefaultServicePostNotDefined,
} from "../openapi/queries";
import { useState } from "react";
import { queryClient } from "./queryClient";
import { SuspenseParent } from "./components/SuspenseParent";
function App() {
const [tags, _setTags] = useState<string[]>([]);
const [limit, _setLimit] = useState<number>(10);
const { data, error, refetch } = useDefaultServiceFindPets({ tags, limit });
// This is an example of a query that is not defined in the OpenAPI spec
// this defaults to any - here we are showing how to override the type
// Note - this is marked as deprecated in the OpenAPI spec and being passed to the client
const { data: notDefined } = useDefaultServiceGetNotDefined<undefined>();
const { mutate: mutateNotDefined } =
useDefaultServicePostNotDefined<undefined>();
const { mutate: addPet } = useDefaultServiceAddPet();
if (error)
return (
<div>
<p>Failed to fetch pets</p>
<button onClick={() => refetch()}>Retry</button>
</div>
);
return (
<div className="App">
<h1>Pet List</h1>
<ul>
{data instanceof Array &&
data?.map((pet, index) => (
<li key={pet.id + "-" + index}>{pet.name}</li>
))}
</ul>
<button
onClick={() => {
addPet(
{
requestBody: { name: "Duggy" },
},
{
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: [useDefaultServiceFindPetsKey],
});
console.log("success");
},
onError: (error) => console.error(error),
}
);
}}
>
Create a pet
</button>
<div>
<h1>Suspense Components</h1>
<SuspenseParent />
</div>
</div>
);
}
export default App;