preact/compose-with-tanstack-query

Implement server-side data loading for Preact tables with TanStack Query.

28.3k|3.6k|Updated Oct 20, 2016
One-click install
npx skills add https://github.com/TanStack/table --skill preact-compose-with-tanstack-query
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: preact/compose-with-tanstack-query
Source: https://github.com/TanStack/table/tree/main/packages/preact-table/skills/preact/compose-with-tanstack-query
Command: npx skills add https://github.com/TanStack/table --skill preact-compose-with-tanstack-query

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building server-side datagrids in Preact often leads to hard-to-manage async flows, inconsistent UI states between page/sort/filter changes, and extra client-side work when the server is already slicing the data.

Core Features & Use Cases

  • Reactive query keys from external atoms: Drive fetches from pagination/sorting/filtering atoms so requests stay in sync with table state.
  • Server-owned manual slicing: Use manualPagination, manualSorting, and manualFiltering for the slices the server owns, while computing rowCount from the server response.
  • Smooth UX with keepPreviousData: Prevent “0 rows flash” by using placeholderData: keepPreviousData during transitions.
  • Practical use case: Fetch paginated rows for a table UI where changing page number, sort order, or filters immediately triggers a refetch with the correct cache key.

Quick Start

Apply the preact/compose-with-tanstack-query recipe to wire useQuery to your table atoms, include keepPreviousData, and ensure your server fetchData returns both rows and rowCount.

Frequently Asked Questions about preact/compose-with-tanstack-query

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

FAQPage Schema
How do I implement server-side pagination in Preact using TanStack Query?

Implement server-side pagination by using TanStack Query with a reactive queryKey containing pagination atoms, setting manualPagination to true, and returning rowCount from your server fetch to ensure correct page calculations.

How do I prevent empty table flashes during remote sorting and filtering transitions?

Prevent empty table flashes during remote sorting and filtering transitions by setting placeholderData to keepPreviousData in your query configuration, maintaining the previous dataset visibility while new async table data loads.

Why does my Preact data table show zero rows when changing pages with TanStack Query?

Your Preact data table shows zero rows because the query cache resets during page changes. Use placeholderData: keepPreviousData to hold the previous rows and include reactive queryKey values to prevent empty flashes.

Does TanStack Query work with Preact for remote data slicing and async table state?

TanStack Query works with Preact for remote data slicing by wiring useQuery to table atoms. Set manualSorting and manualFiltering to true for server-owned slices and compute rowCount from the server response for accurate state.

What's the best way to sync TanStack Query requests with Preact table filter state?

The best way to sync TanStack Query requests with Preact table filter state is building a reactive queryKey that includes pagination, sorting, and filtering atoms, triggering automatic refetches when table state changes.

When do I need manualPagination and manualSorting for Preact datagrids?

You need manualPagination and manualSorting for Preact datagrids when your server handles data slicing and sorting. Setting these to true tells the table to stop client-side processing and rely on server-owned remote state transitions.