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'sAsyncResult:Initial,SuccessorFailure. A failure holds the fullCause, so its error keeps its type, such asTodoNotFound. - Nothing retries by default. A failed fetch fails at once, unless you
give
retryaSchedule. - Queries are defined once, at module level. A query is a value, like a
schema:
todosis 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 Query | Effetch 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, gcTime | staleTime, gcTime, as Effect durations such as "30 seconds"; gcTime is set per query, with no client default |
refetchOnWindowFocus | refetchOnFocus |
retry: 3 | retry: Schedule (default none) |
placeholderData from the cache | placeholder on api.query, Query.make / Query.family |
useInfiniteQuery, fetchNextPage | api.infiniteQuery, useInfiniteQuery, InfiniteQuery.fetchNextPage |
useInfiniteQuery's fields, useSuspenseInfiniteQuery's | useInfiniteQueryState, useSuspenseInfiniteQueryState: the fields with the page controls |
getNextPageParam, getPreviousPageParam | nextPageParam, previousPageParam (return undefined / null for none) |
experimental_streamedQuery | Query.stream, Query.streamFamily; api.query of an SSE or NDJSON endpoint |
setQueryData from a WebSocket's messages | live on api.query, Query.make / Query.family |
React
Reading queries in components maps as follows:
| TanStack Query | Effetch Query |
|---|---|
QueryClientProvider | QueryProvider |
useQueryClient | useQueryClient, which returns the nearest provider's client |
useQuery, useSuspenseQuery | useQuery returns an AsyncResult; useSuspenseQuery returns its Success |
useQuery's data, error, isPending, isFetching, refetch | useQueryState: the same fields, with status narrowing data and error. status is "pending", "success" or "failure", and isError is isFailure |
useSuspenseQuery's fields | useSuspenseQueryState: the same fields, with data always there |
select | select on useQuery, useSuspenseQuery and useQueryState; Atom.map to share it |
enabled: false | useQuery(null) |
placeholderData: keepPreviousData | useQuery(query, { keepPrevious: true }) |
isPlaceholderData | isPlaceholder on useQueryState |
useQueries | useQueries |
useQueries's fields | useQueriesState: an object of fields per query |
subscribed: false | paused: true on useQuery, useQueryState, useQueries and useInfiniteQuery |
useQueryErrorResetBoundary with an error boundary and Suspense | QueryBoundary; with a router's boundary, useResetQueryFailure |
useIsFetching | useIsFetching |
Mutations
Defining and running mutations maps as follows:
| TanStack Query | Effetch Query |
|---|---|
useMutation, mutationOptions | useMutation(api.mutation(endpoint, { … })), or Mutation.make |
mutate(variables, { onSuccess, onError }) | run(variables, { onSuccess, onFailure }) |
useMutation's status, data, error, isPending | The same fields on useMutation, beside result. status is "idle", "pending", "success" or "failure", and isError is isFailure |
useMutation's variables; mutation scope | variables; concurrent: "queue" (per useMutation) |
invalidateQueries in a mutation's onSuccess | invalidates on the mutation; fromClient(ApiClient, { invalidates: "route" }) for every endpoint |
onMutate returning a rollback context | optimistic, undone automatically |
useIsMutating, useMutationState | Same names; useMutationState(mutation) lists one mutation's runs in progress |
The cache
Reading and writing the cache maps as follows:
| TanStack Query | Effetch Query |
|---|---|
getQueryData, setQueryData | Query.get, Query.set / Query.update (Effects); QueryClient.get(client, query) |
setQueriesData | Query.update(family, (value, args) => …) |
invalidateQueries, refetchQueries, resetQueries | Query.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 onSuccess | entities: { sync: [Todos] } on the client |
The client
Creating and configuring the client maps as follows:
| TanStack Query | Effetch 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, onlineManager | The 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 Query | Effetch Query |
|---|---|
dehydrate, hydrate, HydrationBoundary | QueryClient.dehydrate, QueryClient.hydrate, HydrationBoundary. A Query.make or Query.family query needs a schema; an endpoint query uses its output |
setupRouterSsrQueryIntegration | connectQueryClient (./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
- Getting started: build a small todo app, a file at a time.
- Queries from endpoints: define the queries your app reads.
- Limitations: what Effetch Query 0.1 doesn't do.