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
Copy file name to clipboardExpand all lines: docs/graphql.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -13,4 +13,4 @@ You can use [GraphQL-Codegen](https://graphql-code-generator.com/) to generate r
13
13
14
14
## Examples
15
15
16
-
-[basic-graphql-request](../docs/examples/basic-graphql-request) (The "basic" example, but implemented with [`graphql-request`](https://github.com/prisma-labs/graphql-request))
16
+
-[basic-graphql-request](../examples/react/basic-graphql-request) (The "basic" example, but implemented with [`graphql-request`](https://github.com/prisma-labs/graphql-request))
Copy file name to clipboardExpand all lines: docs/typescript.md
+61-4Lines changed: 61 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -12,16 +12,73 @@ Things to keep in mind:
12
12
- It is **highly recommended that you lock your react-query package version to a specific patch release and upgrade with the expectation that types may be fixed or upgraded between any release**
13
13
- The non-type-related public API of React Query still follows semver very strictly.
14
14
15
-
## Defining Custom Hooks
15
+
## Type Inference
16
16
17
-
When defining a custom hook you need to specify the result and error types, for example:
17
+
Types in React Query generally flow through very well so that you don't have to provide type annotations for yourself
This works best if your `queryFn` has a well-defined returned type. Keep in mind that most data fetching libraries return `any` per default, so make sure to extract it to a properly typed function:
React Query uses a [discriminated union type](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#discriminated-unions) for the query result, discriminated by the `status` field and the derived status boolean flags. This will allow you to check for e.g. `success` status to make `data` defined:
The type for error defaults to `unknown`. This is in line with what TypeScript gives you per default in a catch clauses (see [useUnknownInCatchVariables](https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#use-unknown-catch-variables)). The safest way to work with `error` would be to perform a runtime check; another way would be to explicitly define types for `data` and `error`:
0 commit comments