Skip to Content
Effetch Query

Coming from TanStack Query

How TanStack Query's ideas and names map to Effetch Query.

You know TanStack Query, and you want to know what's the same here and what isn't. Most of what you know carries over: the vocabulary is the same, and so are many of the names. A few things work differently:

  • A result is an AsyncResult. Reading a query gives Effect's AsyncResult: Initial, Success or Failure. A failure holds the full Cause, so its error keeps its type, such as TodoNotFound.
  • Nothing retries by default. A failed fetch fails at once, unless you give retry a Schedule.
  • Queries are defined once, at module level. A query is a value, like a schema: todos is defined once and shared, not written out with its key in each component.
  • Offline pauses nothing. There's no networkMode: a fetch that runs while the device is offline fails, and the queries in use that are stale refetch when it reconnects.

Each of the following sections maps one part of TanStack Query's API to Effetch Query's, in the order of the sidebar, and links each to the page that explains it.

Queries

Defining and fetching queries maps as follows:

TanStack QueryEffetch Query
queryOptions({ queryKey, queryFn })api.query(endpoint), or Query.make / Query.family({ key, run })
query(); ensureQueryData, fetchQuery (deprecated since 5.102)Query.fetch; outside Effect, client.fetch
prefetchQuery (deprecated since 5.102)Query.prefetch; outside Effect, client.prefetch
staleTime, gcTimestaleTime, gcTime, as Effect durations such as "30 seconds"; gcTime is set per query, with no client default
refetchOnWindowFocusrefetchOnFocus
retry: 3retry: Schedule (default none)
placeholderData from the cacheplaceholder on api.query, Query.make / Query.family
useInfiniteQuery, fetchNextPageapi.infiniteQuery, useInfiniteQuery, InfiniteQuery.fetchNextPage
useInfiniteQuery's fields, useSuspenseInfiniteQuery'suseInfiniteQueryState, useSuspenseInfiniteQueryState: the fields with the page controls
getNextPageParam, getPreviousPageParamnextPageParam, previousPageParam (return undefined / null for none)
experimental_streamedQueryQuery.stream, Query.streamFamily; api.query of an SSE or NDJSON endpoint
setQueryData from a WebSocket's messageslive on api.query, Query.make / Query.family

React

Reading queries in components maps as follows:

TanStack QueryEffetch Query
QueryClientProviderQueryProvider
useQueryClientuseQueryClient, which returns the nearest provider's client
useQuery, useSuspenseQueryuseQuery returns an AsyncResult; useSuspenseQuery returns its Success
useQuery's data, error, isPending, isFetching, refetchuseQueryState: the same fields, with status narrowing data and error. status is "pending", "success" or "failure", and isError is isFailure
useSuspenseQuery's fieldsuseSuspenseQueryState: the same fields, with data always there
selectselect on useQuery, useSuspenseQuery and useQueryState; Atom.map to share it
enabled: falseuseQuery(null)
placeholderData: keepPreviousDatauseQuery(query, { keepPrevious: true })
isPlaceholderDataisPlaceholder on useQueryState
useQueriesuseQueries
useQueries's fieldsuseQueriesState: an object of fields per query
subscribed: falsepaused: true on useQuery, useQueryState, useQueries and useInfiniteQuery
useQueryErrorResetBoundary with an error boundary and SuspenseQueryBoundary; with a router's boundary, useResetQueryFailure
useIsFetchinguseIsFetching

Mutations

Defining and running mutations maps as follows:

TanStack QueryEffetch Query
useMutation, mutationOptionsuseMutation(api.mutation(endpoint, { … })), or Mutation.make
mutate(variables, { onSuccess, onError })run(variables, { onSuccess, onFailure })
useMutation's status, data, error, isPendingThe same fields on useMutation, beside result. status is "idle", "pending", "success" or "failure", and isError is isFailure
useMutation's variables; mutation scopevariables; concurrent: "queue" (per useMutation)
invalidateQueries in a mutation's onSuccessinvalidates on the mutation; fromClient(ApiClient, { invalidates: "route" }) for every endpoint
onMutate returning a rollback contextoptimistic, undone automatically
useIsMutating, useMutationStateSame names; useMutationState(mutation) lists one mutation's runs in progress

The cache

Reading and writing the cache maps as follows:

TanStack QueryEffetch Query
getQueryData, setQueryDataQuery.get, Query.set / Query.update (Effects); QueryClient.get(client, query)
setQueriesDataQuery.update(family, (value, args) => …)
invalidateQueries, refetchQueries, resetQueriesQuery.invalidate, Query.refetch, Query.reset: a query, a family, a key prefix or a group. Query.refetch reaches only the queries in use
removeQueries, queryClient.clear()Query.clear, client.clear(): drops the values without fetching
A record in many queries (normalized caches, TanStack DB)Entity.update, Entity.set, Entity.remove, Entity.get
setQueryData on other queries in a query's onSuccessentities: { sync: [Todos] } on the client

The client

Creating and configuring the client maps as follows:

TanStack QueryEffetch Query
new QueryClient({ defaultOptions })QueryClient.make({ queries: { defaults }, mutations: { defaults } })
QueryCache({ onError, onSuccess, onSettled })queries.onFailure, queries.onSuccess, queries.onSettled
MutationCache({ onMutate, onError, … })mutations.onMutate, mutations.onFailure, …
focusManager, onlineManagerThe client's signals (Signals.browser, reactNativeSignals). They trigger refetches only: being offline pauses nothing

Server rendering

Sending the cache from a server maps as follows:

TanStack QueryEffetch Query
dehydrate, hydrate, HydrationBoundaryQueryClient.dehydrate, QueryClient.hydrate, HydrationBoundary. A Query.make or Query.family query needs a schema; an endpoint query uses its output
setupRouterSsrQueryIntegrationconnectQueryClient (./react/tanstack-router)

Not in 0.1

These have no equivalent in 0.1:

  • cancelQueries;
  • networkMode, and the pausing of queries and mutations while offline;
  • devtools.

Limitations lists everything 0.1 doesn't do, and what to do instead.

What's next

On this page