Skip to content

fix docs typos #1836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions packages/openapi-react-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It works by using [openapi-fetch](../openapi-fetch) and [openapi-typescript](../
- ✅ All parameters, request bodies, and responses are type-checked and 100% match your schema
- ✅ No manual typing of your API
- ✅ Eliminates `any` types that hide bugs
- ✅ Also eliminates `as` type overrides that can also hide bugs
- ✅ Eliminates `as` type overrides that can also hide bugs

## Setup

Expand All @@ -25,42 +25,42 @@ Next, generate TypeScript types from your OpenAPI schema using openapi-typescrip
npx openapi-typescript ./path/to/api/v1.yaml -o ./src/lib/api/v1.d.ts
```

> ⚠️ Be sure to <a href="https://redocly.com/docs/cli/commands/lint/" target="_blank" rel="noopener noreferrer">validate your schemas</a>! openapi-typescript will err on invalid schemas.
> ⚠️ Be sure to <a href="https://redocly.com/docs/cli/commands/lint/" target="_blank" rel="noopener noreferrer">validate your schemas</a>! openapi-typescript will error on invalid schemas.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“err“ is correct; that is a verb. “Error” is a noun, so this isn’t correct.

However, this sentence only applies to 6.x, not 7.x (since that will validate). So we could just remove this altogether.


## Usage

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.
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.

```tsx
import createFetchClient from "openapi-fetch";
import createClient from "openapi-react-query";
import type { paths } from "./my-openapi-3-schema"; // generated by openapi-typescript
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use double quotes in this repository and I think we should keep documentation with the same rules (default biome ones)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks. My autoformat on save was the culprit, lol.

import createFetchClient from 'openapi-fetch';
import createClient from 'openapi-react-query';
import type { paths } from './my-openapi-3-schema'; // generated by openapi-typescript

const fetchClient = createFetchClient<paths>({
baseUrl: "https://myapi.dev/v1/",
baseUrl: 'https://myapi.dev/v1/',
});
const $api = createClient(fetchClient);

const MyComponent = () => {
const { data, error, isLoading } = $api.useQuery(
"get",
"/blogposts/{post_id}",
const { data, error, isPending } = $api.useQuery(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { data, error, isPending } = $api.useQuery(
const { data, error, isLoading } = $api.useQuery(

? I’m confused; this should be isLoading, shouldn’t it? Why the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have v5 as a peer dependency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks for explaining! I missed that. I think we have some other docs out-of-date, then. This is good for now!

'get',
'/blogposts/{post_id}',
{
params: {
path: { post_id: 5 },
},
},
}
);

if (isLoading || !data) return "Loading...";
if (isPending || !data) return 'Loading...';

if (error) return `An error occured: ${error.message}`;
if (error) return `An error occurred: ${error.message}`;

return <div>{data.title}</div>;
};
```

> You can find more information about `createFetchClient` on the [openapi-fetch documentation](../openapi-fetch).
> You can find more information about `createFetchClient` in the [openapi-fetch documentation](../openapi-fetch).

## 📓 Docs

Expand Down