compositions/router-query

Coordinate TanStack Router data flows with TanStack Query for caching and hydration.

14.9k|1.8k|Updated Jan 14, 2019
One-click install
npx skills add https://github.com/TanStack/router --skill compositions-router-query
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compositions/router-query
Source: https://github.com/TanStack/router/tree/main/packages/react-router/skills/compositions/router-query
Command: npx skills add https://github.com/TanStack/router --skill compositions-router-query

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Coordinating TanStack Router navigations with TanStack Query to centralize data caching and hydration.

Core Features & Use Cases

  • Data-coordinated routing: loader data is backed by Query's cache, with per-request isolation in SSR setups.
  • SSR hydration & streaming: automatic dehydration/hydration of query state across server and client.
  • UseSuspenseQuery integration: components subscribe to cache updates with minimal loading states.

Quick Start

Instantiate a QueryClient, attach it to the router context, and use ensureQueryData with useSuspenseQuery in route components.

Frequently Asked Questions about compositions/router-query

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I coordinate TanStack Router loaders with TanStack Query for SSR data hydration?

To coordinate TanStack Router loaders with TanStack Query, you back loader data with Query's cache, attach a QueryClient to the router context, and use ensureQueryData with useSuspenseQuery to handle automatic dehydration and hydration across server and client.

What is the best way to isolate QueryClient data per-request in an SSR setup?

Isolating QueryClient data per-request in SSR requires instantiating a new QueryClient for each request and attaching it to the router context, ensuring server-side query caches do not bleed between users before dehydration and client hydration.

Does TanStack Router work with useSuspenseQuery to minimize route loading states?

Yes, TanStack Router works with useSuspenseQuery by allowing route components to subscribe directly to the centralized Query cache, rendering data synchronously when available and triggering suspense boundaries only when cache is missing.

How do I stream SSR route data using TanStack Query and TanStack Router?

Streaming SSR route data with TanStack Query involves using the router loader to ensureQueryData on the server, automatically dehydrating the query state, and hydrating it on the client as the stream arrives to maintain cache synchronization.

Can I cache route loader data in TanStack Query instead of managing router state directly?

Yes, you can cache route loader data in TanStack Query by calling ensureQueryData inside the router loader function, centralizing the data cache in Query and allowing route components to read from it via useSuspenseQuery.

Why does my TanStack Router SSR setup lose query data during hydration?

TanStack Router SSR setups lose query data during hydration if the server-side QueryClient state is not properly dehydrated and passed to the client, requiring you to attach the QueryClient to the router context for automatic state synchronization.