TanStack Query is an async state manager, not a data fetching library. You provide a queryFn that returns a Promise; React Query handles caching, deduplication, background updates, and stale data management.
When to use: Infinite scrolling, offline-first apps, auto-refetching on focus/reconnect, complex cache invalidation, React Native, hybrid server/client apps.
When NOT to use: Purely synchronous state (useState/Zustand), normalized GraphQL caching (Apollo/urql), server-components-only apps (native fetch), simple fetch-and-display (server components).
用於 React 的 TanStack Query v5 伺服器狀態管理。涵蓋查詢/突變模式、v4 到 v5 遷移(物件語法、gcTime、isPending、keepPreviousData)、透過 useMutationState 進行樂觀更新、具有 HydrationBoundary 的 SSR/Hydration、無限查詢、離線/PWA 支援、具有 throwOnError 的錯誤邊界以及 React 19 整合。 在建構資料擷取、修復遷移錯誤、調試水合不匹配、實施快取策略或配置突變時使用。 來源:oakoss/agent-skills。