Skip to content

secondsky/claude-skills / plugins/tanstack-query/skills/tanstack-query

tanstack-query

Verified

TanStack Query v5 (React Query) server state management. Use for data fetching, caching, mutations, or encountering v4 migration, stale data, invalidation errors.

templates/query-client-config.ts

View on GitHub
// src/lib/query-client.ts
import { QueryClient } from '@tanstack/react-query'

/**
 * QueryClient configuration for TanStack Query v5
 *
 * Key settings:
 * - staleTime: How long data is fresh (won't refetch)
 * - gcTime: How long inactive data stays in cache (garbage collection time)
 * - retry: Number of retry attempts on failure
 * - refetchOnWindowFocus: Refetch when window regains focus
 */
export const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      // Data is fresh for 5 minutes (won't refetch during this time)
      staleTime: 1000 * 60 * 5,

      // Inactive data stays in cache for 1 hour before garbage collection
      gcTime: 1000 * 60 * 60,

      // Retry failed requests with smart logic
      retry: (failureCount, error) => {
        // Don't retry on 404s
        if (error instanceof Response && error.status === 404) {
          return false
        }
        // Retry up to 3 times for other errors
        return failureCount < 3
      },

      // Don't refetch on window focus (can be annoying during dev)
      // Set to true for real-time data (stock prices, notifications)
      refetchOnWindowFocus: false,

      // Refetch when network reconnects
      refetchOnReconnect: true,

      // Refetch on component mount if data is stale
      refetchOnMount: true,
    },
    mutations: {
      // Don't retry mutations by default (usually not wanted)
      retry: 0,

      // Global mutation error handler (optional)
      onError: (error) => {
        console.error('Mutation error:', error)
        // Add global error handling here (toast, alert, etc.)
      },
    },
  },
})

/**
 * Adjust these settings based on your needs:
 *
 * For real-time data (stock prices, notifications):
 * - staleTime: 0 (always stale, refetch frequently)
 * - refetchOnWindowFocus: true
 * - refetchInterval: 1000 * 30 (refetch every 30s)
 *
 * For static data (user settings, app config):
 * - staleTime: Infinity (never stale)
 * - refetchOnWindowFocus: false
 * - refetchOnMount: false
 *
 * For moderate data (todos, posts):
 * - staleTime: 1000 * 60 * 5 (5 minutes)
 * - refetchOnWindowFocus: false
 * - refetchOnMount: true
 */
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall