React Query is now written in TypeScript to make sure the library and your projects are type-safe!
Things to keep in mind:
When defining a custom hook you need to specify the result and error types, for example:
function useGroups() {
return useQuery<Group[], Error>('groups', fetchGroups)
}
function useGroups() {
return useQuery<Group[], Error>('groups', fetchGroups)
}
For tips and tricks around type inference, have a look at React Query and TypeScript from the Community Resources.
“This course is the best way to learn how to use React Query in real-world applications.”—Tanner LinsleyGet the course