You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once your types have been generated from your schema, you can create a [fetch client](../openapi-fetch), a react-query client and start querying your API.
33
33
34
34
```tsx
35
-
importcreateFetchClientfrom'openapi-fetch';
36
-
importcreateClientfrom'openapi-react-query';
37
-
importtype { paths } from'./my-openapi-3-schema'; // generated by openapi-typescript
35
+
importcreateFetchClientfrom"openapi-fetch";
36
+
importcreateClientfrom"openapi-react-query";
37
+
importtype { paths } from"./my-openapi-3-schema"; // generated by openapi-typescript
38
38
39
39
const fetchClient =createFetchClient<paths>({
40
-
baseUrl: 'https://myapi.dev/v1/',
40
+
baseUrl: "https://myapi.dev/v1/",
41
41
});
42
42
const $api =createClient(fetchClient);
43
43
44
44
const MyComponent = () => {
45
45
const { data, error, isPending } =$api.useQuery(
46
-
'get',
47
-
'/blogposts/{post_id}',
46
+
"get",
47
+
"/blogposts/{post_id}",
48
48
{
49
49
params: {
50
50
path: { post_id: 5 },
51
51
},
52
52
}
53
53
);
54
54
55
-
if (isPending||!data) return'Loading...';
55
+
if (isPending||!data) return"Loading...";
56
56
57
57
if (error) return`An error occurred: ${error.message}`;
0 commit comments