useState/context, not this library.useQuery. Writing data (create/update/delete/side-effect) → useMutation. Never fetch-with-side-effects inside useMutation's mutationFn as a substitute for a real query.setQueryData, skip the refetch. Otherwise → invalidateQueries from onSuccess.variables/isPending off the mutation. Needed in several places → cache-write in onMutate + rollback in onError.enabled: !!value. But check first whether a combined backend endpoint would remove the dependency entirely.useSuspenseQuery in a component → merge into one useSuspenseQueries call. Never leave them side by side — they'll serialize.placeholderData: keepPreviousData. Prevents the loading-flash between keys.dehydrate, <HydrationBoundary>, non-zero staleTime. Never construct QueryClient at module scope in an SSR app.persistQueryClient. Only some queries, or different maxAge per query → experimental_createQueryPersister.| Setting | Default | Notes |
|---|---|---|
staleTime | 0 | Data is stale immediately unless set otherwise |
gcTime | 5 min (client), Infinity (server) | Independent of staleTime |
Query retry | 3, exponential backoff (client); 0 (server) | |
Mutation retry | 0 | Opt-in, unlike queries |
networkMode | 'online' | Pauses instead of failing when offline |
refetchOnWindowFocus/Mount/Reconnect | true | Only fires if data is stale |
notifyOnChangeProps | tracked (Proxy-based) | 'all' opts out |
structuralSharing | true | JSON-compatible data only |
Persisted cache maxAge | 24 hours | Raise gcTime to match, or GC discards it early |
status vs. fetchStatus quick referencestatus | fetchStatus | |
|---|---|---|
| Answers | "Do we have data?" | "Is the fetcher running right now?" |
| Values | pending / error / success | fetching / paused / idle |
| Derived flags | isPending/isError/isSuccess | isFetching/isPaused |
| Combined flag | — | isLoading = isPending && isFetching; isRefetching = isFetching && !isPending |
| Old | New |
|---|---|
cacheTime | gcTime |
useErrorBoundary | throwOnError |
status: 'loading' / isLoading | status: 'pending' / isPending |
keepPreviousData: true | placeholderData: keepPreviousData |
<Hydrate> | <HydrationBoundary> |
fetchQuery/prefetchQuery | queryClient.query() |
exhaustive-deps (fixable) · stable-query-client (fixable) · no-rest-destructuring · no-void-query-fn — install flat/recommended and get all of these plus more.