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 all commits
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
16 changes: 7 additions & 9 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,11 +25,9 @@ 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.

## 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";
Expand All @@ -42,25 +40,25 @@ const fetchClient = createFetchClient<paths>({
const $api = createClient(fetchClient);

const MyComponent = () => {
const { data, error, isLoading } = $api.useQuery(
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