Skip to main content

TanStack Query Config Builder

Configure your TanStack Query (React Query v5) setup visually. Set staleTime, gcTime, retry logic, and generate production-ready TypeScript code for your QueryClient and hooks.

✓ staleTime / gcTime calculator ✓ QueryClient config generator ✓ useQuery + useMutation code

Presets

Cache Timing

0 ms (immediate)
0 (always stale)1h∞
5 min
30s5min∞

Query Settings

Cache Lifecycle

Generated Code

 

Frequently Asked Questions

What is TanStack Query (React Query)?▼

TanStack Query is an async state management library for React (and other frameworks). It handles fetching, caching, background updates, and synchronization of server state. Instead of manually managing loading/error/data state with useState and useEffect, you call useQuery and let the library handle everything.

What is staleTime?▼

staleTime is how long (in ms) fetched data is considered fresh. During this window, React Query won't refetch the data — it serves the cached version. After staleTime expires, data is considered stale, and React Query will refetch when the query is re-used (e.g., on window focus or component mount).

What is gcTime (formerly cacheTime)?▼

gcTime (garbage collection time) is how long inactive query data stays in memory after all components using it unmount. Once gcTime expires, the cache entry is removed. gcTime should always be ≥ staleTime. Default is 5 minutes. Setting it to Infinity keeps data in memory until page reload.

When should I use initialData vs placeholderData?▼

initialData is treated as real data — it counts as a successful cache entry, respects staleTime, and won't trigger a background fetch if still fresh. placeholderData is UI-only — it's shown while the query loads but never persisted to the cache. Use initialData for SSR-hydrated data, placeholderData for skeleton/preview content.

What does retry do?▼

retry controls how many times React Query retries a failed request before marking the query as error state. Default is 3. Each retry uses exponential backoff (retryDelay). Set to false to disable retries (useful for user-input queries where immediate feedback is needed).

How do I use QueryClient globally?▼

Create a QueryClient instance outside your component tree and pass it to QueryClientProvider at your app root. You can access it with useQueryClient() hook inside components for manual invalidation, prefetching, or setting cached data. For SSR/Next.js, create a new QueryClient per request to avoid shared state between users.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →