@monarcode/effetch-query/react/tanstack-router
Every export of the TanStack Router entry point: connecting a client to a router, and so to TanStack Start.
@monarcode/effetch-query/react/tanstack-router connects a query client to a TanStack Router, and so to TanStack Start. Import what you use:
import { } from "@monarcode/effetch-query/react/tanstack-router";Its exports follow, grouped by the guide that covers them, each with its docs. Your editor shows the same docs, with an example, when you hover the name.
TanStack Router and Start
Guide: TanStack Router and Start.
connectQueryClient
Connects a query client to a TanStack Router (and so TanStack Start), as TanStack's setupRouterSsrQueryIntegration does for TanStack Query. Call it where the router is made: Start's getRouter, or your server and browser entries.
- On the server, the queries your loaders loaded go with the page, and queries started while rendering follow as they start, those still loading as promises the browser waits for, so nothing is fetched twice. The client is disposed when the request ends: make one per request from a process-wide
ManagedRuntime(QueryClient.make({ runtime })), so your app's layer is built once rather than per request (see the example). - In the browser, they load into the client before React hydrates, with no
HydrationBoundary. - Redirects: a query or mutation that fails or dies with a router
redirect()navigates there, in the browser. Write it asEffect.die(redirect({ to: "/login" })), to keep it out of the error type, inside the Effect so each run makes its own: the router resolves a redirect in place. A fetch an Effect awaits (Query.fetchorQuery.prefetch) is left to it: in a loader,client.fetchrejects with the redirect and the router follows it, and a preload's is dropped, as the router drops it. So load a query that may redirect withclient.fetch: one only prefetched fails in its readers instead.
Load data in loaders with context.queryClient.fetch(query), which returns a fresh value without fetching, and set the router's defaultPreloadStaleTime to 0, so the queries' staleTime decides what's refetched rather than the router's own loader cache. Only queries with a schema cross to the browser. A dehydrate.queries key that holds a query, a family or a group fails each server render with a Query.KeyHoldsTargetError.
ConnectDehydrateOptions
Which queries connectQueryClient sends from the server, as QueryClient.DehydrateOptions chooses them. Queries still loading are always sent, as promises the browser waits for: the router's serializer carries them.
Prop
Type
ConnectQueryClientOptions
Options for connectQueryClient.
Prop
Type