lazy-prefetch-pattern

Implement lazy prefetching of React Query v5 data for TSX components.

1.2k|116|Updated Mar 22, 2025
One-click install
npx skills add https://github.com/FranciscoMoretti/sparka --skill lazy-prefetch-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: lazy-prefetch-pattern
Source: https://github.com/FranciscoMoretti/sparka/tree/main/.claude/skills/lazy-prefetch-pattern
Command: npx skills add https://github.com/FranciscoMoretti/sparka --skill lazy-prefetch-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

React Query v5 lazy prefetch (dehydrate pending queries) helps ensure TSX components render with data already available, reducing initial load time and UI jank.

Core Features & Use Cases

  • Lazy Prefetching: Prefetch data for pending queries in TSX files using React Query v5.
  • Dehydration: Dehydrate the query cache for fast hydration on client render.
  • Use Case: When navigating to a route that renders a TSX component, prefetch the needed data so the UI appears instantly.

Quick Start

Enable lazy prefetching for all *.tsx files and dehydrate pending queries in the project.

Frequently Asked Questions about lazy-prefetch-pattern

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

FAQPage Schema
How do I reduce initial load time in React Query TSX components?

Lazy prefetching reduces initial load time by preloading React Query v5 data before TSX components render. Dehydrate pending queries on the server and hydrate on the client to eliminate waterfalls and render with data already available.

What is lazy prefetching in React Query v5?

Lazy prefetching is a React Query v5 technique that defers data fetching until needed, then captures pending queries using dehydrate() for fast hydration. This reduces UI jank by ensuring data is ready when components mount.

Can I use React Query v5 lazy prefetch with SSR workflows?

Yes. React Query v5 lazy prefetch integrates with SSR hydration workflows by dehydrating the query cache on the server and rehydrating on the client, enabling TSX components to render instantly with preloaded data.

How do I prefetch data for route navigation in React?

Use React Query v5 lazy prefetch to preload data when navigating to routes that render TSX components. Dehydrate the query cache before navigation and hydrate on client render to avoid loading spinners.

Does lazy prefetching work with existing React Query query clients?

Yes. Lazy prefetching seamlessly integrates with existing React Query query clients in TSX files. Use dehydrate() to capture pending queries and integrate with your current query setup without refactoring.

When should I use dehydrate() instead of standard React Query prefetching?

Use dehydrate() for SSR and route-level preloading scenarios where you need to serialize the query cache and hydrate on the client. It's ideal for component-level prefetch on mount and reducing initial navigation latency in TSX applications.