React Query is now written in TypeScript to make sure the library and your projects are type-safe!

Install the latest version to get React Query with the new types:

npm install react-query --save


  • The query results are no longer discriminated unions, which means you have to check the actual data and error properties.
  • Requires TypeScript v3.8 or greater

Defining Custom Hooks

When defining a custom hook you need to specify the result and error types, for example:

export function useGroups() {
return useQuery<Group[], Error>(
() => fetch(`/api/groups`).then(res => res.json())
Was this page helpful?

Subscribe to our newsletter

The latest TanStack news, articles, and resources, sent to your inbox.

    I won't send you spam.

    Unsubscribe at any time.

    © 2020 Tanner Linsley. All rights reserved.