React Query is now written in TypeScript to make sure the library and your projects are type-safe!
Things to keep in mind:
data
property is left as unknown
)When defining a custom hook you need to specify the result and error types, for example:
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.
Fast track your learning and
take the offical React Query course ↗️
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.