gs-tanstack-react-query_skill

This skill helps you manage TanStack React Query with clean architecture, returning DTOs and handling queries, mutations, and cache invalidation.

1

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill gilbertopsantosjr/fullstacknextjs --skill gs-tanstack-react-query

  • SKILL.md4.0 KB

Overview

This skill provides opinionated TanStack React Query integrations following Clean Architecture patterns. It wires server actions to React Query hooks so queries return DTOs and mutations call server actions, with built-in patterns for cache keys, invalidation, optimistic updates, and pagination. Use it to keep data fetching type-safe and aligned with domain boundaries.

How this skill works

Components use hooks like useServerActionQuery, useServerActionMutation, and useServerActionInfiniteQuery that call server actions. Query responses are transformed into DTO types; components never depend on domain entities or direct use case calls. The skill relies on hierarchical query keys and a QueryClient to handle invalidation, optimistic updates, and pagination.

When to use it

  • When you fetch data from server actions and want responses typed as DTOs
  • When using useQuery/useMutation patterns with TanStack React Query
  • When you need structured cache invalidation across lists and details
  • When implementing optimistic UI updates with rollback support
  • When adding cursor-based pagination with infinite queries

Best practices

  • Always type hooks with DTO types (e.g., CategoryDTO) instead of domain entities
  • Call only server actions from components—never invoke use cases directly
  • Design hierarchical query keys for broad invalidation and specific refetches
  • Implement optimistic updates with onMutate/onError/onSettled and store previous state for rollback
  • Invalidate parent keys (e.g., ['categories']) after mutations to keep lists fresh

Example use cases

  • List active categories with useServerActionQuery returning CategoryDTO[]
  • Fetch a single category detail with a key like ['categories','detail',id]
  • Create a category with useServerActionMutation and invalidate ['categories'] on success
  • Update a category optimistically: patch the detail cache, rollback on error, then invalidate
  • Implement infinite scrolling for categories with useServerActionInfiniteQuery and nextCursor

FAQ

Use DTO types for all query and mutation results. Components should only depend on DTO shapes returned by server actions.

How should I structure query keys?

Use hierarchical keys (e.g., ['categories'], ['categories','list',{filters}], ['categories','detail',id]) so you can invalidate broadly or target specific data.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational