Skip to main content
@usenarrator/plugin-tanstack-query The TanStack Query plugin reads a query as its key, the function that fetches it, and the options that decide when it is refetched or thrown away. Options like staleTime, enabled and select become short bullets (“Fresh for 5 minutes”, “Only when ID is set”), and the fields you destructure from the result are named in plain words. Mutations read as what they run and what happens when they succeed, fail or settle.
The plugin declares library: { name: "@tanstack/react-query", versions: ">=4 <6" }. It narrates files that import from a TanStack Query package (React, Vue, Solid, Svelte and Angular adapters included) or belong to a package that depends on one (see Dependency detection). Same-named functions from other libraries are left alone.

Examples

A query with options
English
An infinite query
English
A mutation that refreshes a query
English

Versions

Two things changed meaning between v4 and v5. In v4, isLoading meant “has no data yet”, and in v5 that is isPending, while isLoading means the first fetch is in flight. Queries also stopped calling onSuccess, onError and onSettled in v5. The plugin picks the reading from the major version your package declares, so a v4 codebase reads onSuccess as a step and a v5 codebase is told that the callback is no longer called. Pass version to pin it. See Plugin versioning.
With tanstackQuery({ version: 5 })
English
With tanstackQuery({ version: 4 })
English

What it covers

  • useQuery, useSuspenseQuery, useInfiniteQuery, useQueries, and the create* and inject* forms used by the other adapters.
  • Query options: enabled, staleTime, gcTime, select, placeholderData, refetchInterval, retry, refetch flags and paging options.
  • queryOptions and infiniteQueryOptions, and the v4 positional form useQuery(key, fn, options).
  • useMutation with onMutate, onSuccess, onError and onSettled, including the optimistic update recipe, plus mutate, mutateAsync and reset.
  • The query client: invalidateQueries and its filters, setQueryData, getQueryData, cancelQueries, prefetching, clear and default options.
  • Composition with the tRPC plugin, whose options helpers can be passed straight to useQuery.

Translating

The English phrasebook is exported as en and typed as TanStackQueryPhrases.