Skip to content

Hook libraries

Two independent choices: library is what the hooks wrap; http is what the built-in runtime sends requests with.

library: vue-query # see the table
http: axios # api-client (default) | fetch | axios | angular
target: hooks # "requests" stops at plain request functions
library hooks arguments packages the runtime imports
react-query (default) useXQuery, useXMutation plain values @tanstack/react-query
vue-query useXQuery, useXMutation a value, a ref or a getter @tanstack/vue-query, vue
svelte-query createXQuery, createXMutation a value or a getter @tanstack/svelte-query (v6, Svelte 5)
solid-query createXQuery, createXMutation a value or an accessor @tanstack/solid-query, solid-js
angular-query injectXQuery, injectXMutation a value or a getter (a signal read) @tanstack/angular-query-experimental, @angular/core
swr useXQuery, useXMutation plain values swr, react

In the four reactive libraries an argument is read where the request is made, not once when the hook is called, so the query follows whatever it was given:

const id = ref("1");
const pet = useGetPetQuery(id); // Vue: refetches when `id.value` changes
const pet = createGetPetQuery(() => id()); // Solid / Svelte / Angular: a getter

A query hook takes its path ids as string | undefined and waits for them: it is not enabled until every id is there, so a page can pass a route param or a selection straight in and no request goes to /pets/undefined. The options you pass come last, so enabled can still be forced. Mutations take their variables when mutate is called, so they are the same in every library.

Notes that follow from what each library offers:

  • SWR cannot cancel a request, so the signal a fetcher gets never fires; an infinite list asks for page n at n * pageSize.
  • Solid: the hook options leave out initialData — createQuery has one overload for options that set it and one for options that do not, and options that may do either match neither.
  • Angular: inject… functions need an injection context — a constructor, a field initialiser, a service, runInInjectionContext.