Skip to content

Commit 6e30aaa

Browse files
author
aleris
authored
docs(typescript): add note for custom hooks types (#1185)
When using with typescript, the error type cannot be inferred and appears as 'unknown'. This adds an explicative note and example as it might not be obvious how a custom hook should be created.
1 parent 160d1ac commit 6e30aaa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/src/pages/docs/typescript.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ npm install react-query --save
1515

1616
- The query results are no longer discriminated unions, which means you have to check the actual `data` and `error` properties.
1717
- Requires TypeScript v3.8 or greater
18+
19+
## Defining Custom Hooks
20+
21+
When defining a custom hook you need to specify the result and error types, for example:
22+
23+
export function useGroups() {
24+
return useQuery<Group[], Error>(
25+
'list-groups',
26+
() => fetch(`/api/groups`).then(res => res.json())
27+
)
28+
}

0 commit comments

Comments
 (0)