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
> ⚠️ Be sure to <ahref="https://redocly.com/docs/cli/commands/lint/"target="_blank"rel="noopener noreferrer">validate your schemas</a>! openapi-typescript will err on invalid schemas.
28
+
> ⚠️ Be sure to <ahref="https://redocly.com/docs/cli/commands/lint/"target="_blank"rel="noopener noreferrer">validate your schemas</a>! openapi-typescript will error on invalid schemas.
29
29
30
30
## Usage
31
31
32
-
Once your types has been generated from your schema, you can create a [fetch client](../openapi-fetch), a react-query client and start querying your API.
32
+
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
-
const { data, error, isLoading } =$api.useQuery(
46
-
"get",
47
-
"/blogposts/{post_id}",
45
+
const { data, error, isPending } =$api.useQuery(
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 (isLoading||!data) return"Loading...";
55
+
if (isPending||!data) return'Loading...';
56
56
57
-
if (error) return`An error occured: ${error.message}`;
57
+
if (error) return`An error occurred: ${error.message}`;
58
58
59
59
return <div>{data.title}</div>;
60
60
};
61
61
```
62
62
63
-
> You can find more information about `createFetchClient`on the [openapi-fetch documentation](../openapi-fetch).
63
+
> You can find more information about `createFetchClient`in the [openapi-fetch documentation](../openapi-fetch).
0 commit comments