tanstack-query_skill

This skill helps you configure TanStack Query v5 in React apps, enabling efficient data fetching, caching, optimistic updates, and devtools debugging.
  • Python

24

GitHub Stars

2

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 ovachiever/droid-tings --skill tanstack-query

  • README.md8.0 KB
  • SKILL.md40.8 KB

Overview

This skill helps React developers manage server state with TanStack Query v5. It covers setting up QueryClient, using useQuery/useMutation/useInfiniteQuery, optimistic updates, and v4→v5 migration fixes. Practical tips address renamed options and API changes to avoid common runtime errors.

How this skill works

It configures a centralized QueryClient and wraps your app with QueryClientProvider so hooks can read and update cached server data. The skill demonstrates object-style hook calls (useQuery({queryKey,queryFn})), mutation callbacks (onMutate,onSuccess,onError,onSettled), optimistic updates, and infinite loading via useInfiniteQuery. It also explains key v5 changes like gcTime, isPending, and removed helpers so you can migrate safely.

When to use it

  • Setting up data fetching and caching in a new React 18 app
  • Migrating a codebase from TanStack Query v4 to v5
  • Fixing runtime errors related to object-syntax requirements in hooks
  • Implementing optimistic UI for fast mutation feedback
  • Adding infinite scroll or paginated queries with useInfiniteQuery
  • Tuning cache behavior and refetch policies globally

Best practices

  • Always wrap the app with a single QueryClientProvider and include DevTools inside it
  • Use object syntax for hooks: useQuery({queryKey,queryFn}) and useMutation({mutationFn,...})
  • Prefer sane defaults: set staleTime to avoid excessive refetches and use gcTime (v5) instead of cacheTime
  • Use optimistic updates with onMutate/onError/onSettled and snapshot previous cache to allow rollbacks
  • Structure query keys as arrays and include params for deterministic cache entries
  • Use QueryErrorResetBoundary or React error boundaries to handle query errors gracefully

Example use cases

  • Create reusable query hooks for lists and item details: useTodos() and useTodo(id)
  • Add a todo with optimistic UI and rollback on failure using useMutation and onMutate
  • Migrate existing v4 code: replace cacheTime→gcTime, isLoading→isPending where appropriate, and switch to object syntax
  • Implement infinite scrolling for a feed with useInfiniteQuery and getNextPageParam
  • Configure QueryClient defaultOptions to control retries, staleTime, refetchOnWindowFocus, and gcTime

FAQ

v5 requires object syntax for hooks, renamed cacheTime→gcTime, changed loading flags (use isPending), removed some callbacks and helpers—update call signatures and option names accordingly.

When should I use optimistic updates?

Use optimistic updates for low-risk, fast-feedback actions (toggles, likes, adding lightweight items). Avoid them for critical operations like payments; always snapshot cache to allow rollback on error.

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