frontend-data-fetching
Use when the user asks how to cache server data on the client with TanStack Query, SWR or RTK Query, query keys, staleTime/gcTime, cache invalidation…
от j4flmao★ 47 звёзд на GitHub
Установить frontend-data-fetching в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Frontend Data Fetching
Purpose
Manage server state efficiently on the client — eliminating boilerplate, providing caching, deduplication, background refetching, and optimistic mutations while keeping server state out of global client stores.
Agent Protocol
Trigger
User request includes any of: "data fetching", "TanStack Query", "SWR", "React Query", "server state", "API client", "data fetching pattern", "cache invalidation", "optimistic update", "pagination data", "infinite scroll", "stale-while-revalidate".
Input Context
- Framework (React, Vue, Solid, Svelte)
- Existing state management library
- API patterns (REST, GraphQL, tRPC)
- Auth / token handling approach
Output Artifact
Data fetching architecture with query/mutation patterns and caching strategy.
Response Format
## Strategy
<library, cache-key-design, staleTime>
## Query Layer
<query-hooks, pagination, revalidation>
## Mutation Layer
<optimistic-updates, invalidation, error-handling>
## Cache Config
<staleTime, gcTime, persistence>
—
Compression footer: frontend-data-fetching/v1 | 4 sections | lib: <selected> | cache: <persisted|memory>
No preamble. No postamble. No explanations. No filler/hedging/transitions. Compress output — why use many token when few do trick.
Completion Criteria
- All server data queries cached with appropriate staleTime
- Mutations invalidate related queries or apply optimistic updates
- Pagination / infinite scroll working with loading states
- Error states handled globally and per-query
- Refetch on focus / reconnect configured
Max Response Length
4096 tokens
Data Fetching Decision Trees
Library Selection Decision Tree
Project type?
|-- Complex app with mutations, pagination, optimistic updates?
| |-- YES --> TanStack Query v5
| |-- NO --> Read-heavy, minimal mutations?
| |-- YES --> SWR
| |-- NO --> Using Redux already? --> RTK Query
|-- GraphQL API?
|-- YES --> Apollo Client or urql
|-- NO --> tRPC available? --> tRPC client
Consider: bundle size (~13KB TanStack vs ~4KB SWR), framework support,
devtools quality, cache persistence requirements.
Caching Strategy Decision Tree
Data volatility?
|-- Real-time (chat, notifications) -->
| |-- Polling: refetchInterval: 5000
| |-- WebSocket: integrate with queryClient.setQueryData
|-- Frequently changing (dashboard, feed) -->
| |-- staleTime: 30s, refetchOnWindowFocus: true
|-- Rarely changing (config, reference data) -->
| |-- staleTime: 5min, gcTime: 30min
|-- Never changes (static content) -->
|-- staleTime: Infinity (fetch once, never refetch)
Error Handling Decision Tree
Query error received?
|-- Network error (no response) -->
| |-- Show stale data if available
| |-- Show offline message if no stale data
|-- 4xx (client error) -->
| |-- Do NOT retry (client mistake)
| |-- Show validation error or permission denied
|-- 5xx (server error) -->
|-- Retry with exponential backoff (default 3 times)
|-- Show error state after all retries exhausted
Workflow
1. Library Selection
- TanStack Query (React Query): Complex apps with mutations, optimistic updates, pagination, infinite scroll. Rich devtools. Best for: most production apps.
- SWR: Lightweight, simple API. Good for: small apps, read-heavy, minimal mutation needs.
- RTK Query: Redux ecosystem apps. Tight integration with Redux DevTools. Best for: projects already using Redux.
2. Query Patterns
- Stale-while-revalidate: show cached data, refetch in background.
- Cache-first to network: use cache until explicitly invalidated.
- Refetch on window focus configurable per query (default: true).
- Polling for real-time data via
refetchInterval. - Dependent queries: enable second query only when first has data.
// TanStack Query v5 — basic setup
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 30_000, // 30s before considered stale
gcTime: 5 * 60_000, // 5min unused data stays in cache
retry: 3, // retry 3 times with backoff
refetchOnWindowFocus: true, // refetch when user returns
refetchOnReconnect: true, // refetch on network recovery
},
},
})
function App() {
return (
<QueryClientProvider client={queryClient}>
<AppContent />
</QueryClientProvider>
)
}
3. Mutations
- Optimistic updates: apply new data immediately, rollback on error.
- Invalidate related queries after mutation success.
- Mutation side effects via callbacks:
onMutate,onError,onSettled. - Show optimistic UI state during mutation.
// Optimistic update pattern
function useAddTask() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (newTask: Task) => api.post('/tasks', newTask),
onMut
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/data-fetching-caching-strategies.md
- references/data-fetching-caching.md
- references/data-fetching-error-handling.md
- references/data-fetching-patterns.md
- references/fetching-patterns.md
- references/react-query-patterns.md
- references/swr-patterns.md
- references/tanstack-query.md
FAQ
Что делает скилл frontend-data-fetching?
Use when the user asks how to cache server data on the client with TanStack Query, SWR or RTK Query, query keys, staleTime/gcTime, cache invalidation, optimistic updates, pagination or infinite scroll. Produces a typed data-fetching layer with caching and mutation patterns. Not for backend API design (use backend-api-design).
Как установить скилл frontend-data-fetching?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл frontend-data-fetching запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…