tanstack-query
Skill0 starsChanged 4 months agoMITView on GitHub
How to use TanStack Query v5 for data fetching, mutations, and cache management. Use this whenever creating hooks for API calls — list queries, single-item queries, create/update/delete mutations, or cache invalidation. Covers useQuery, useMutation, query key factories, staleTime defaults, and the service layer pattern.
19 other projects use a version of this.
Adopted by
Most recently taken up by
- yuan-alex/cedartheir own version, first seen Nov 8, 2026
- thongdn-it/react-agent-skillstheir own version, first seen Nov 1, 2026
- kriscard/Skillstheir own version, first seen Nov 1, 2026
- louisbrulenaudet/monorepo-templatetheir own version, first seen Oct 29, 2026
- Firzus/agent-skillstheir own version, first seen Oct 23, 2026
- davidanthonyn/claude-skillstheir own version, first seen Oct 20, 2026
Used with
Projects with it also use tanstack-table, research and 2 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
JasonPaffSkilltanstack-table
Build headless data tables with TanStack Table v8. Server-side pagination, filtering, sorting, and virtualization for Cloudflare Workers + D1. Prevents 12 documented errors.
Also in 3 projects that use this
NVIDIASkillresearch
Before designing a feature, research how comparable libraries solve the problem, check best practices, known pitfalls, and upstream changes. Use when starting a new feature, investigating an unfamiliar area, or the user asks to research something.
Also in 4 projects that use this
SentrySkillreview
Fixture review skill.
Also in 3 projects that use this
GoogleSkillcode-review
Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.
Also in 3 projects that use this
Other versions19 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 19
- Kiranism/next-shadcn-dashboard-starter★ 7.2ksame name
- modrinth/code★ 2.5ksame name
- operately/operately★ 618same name
- Mindrally/skills★ 275same name
- TangleML/tangle-ui★ 104same name
- PyModel/react-frontend-skills★ 23same name
- louisbrulenaudet/monorepo-template★ 19same name
- kriscard/Skills★ 15same name
- thongdn-it/react-agent-skills★ 5same name
- Firzus/agent-skills★ 4same name
9 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository12 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- feature-architectureSkill
- frontend-auditSkill
- frontend-i18nSkill
- mui-themeSkill
- react-coreSkill
- react-standardSkill
- table-mrtSkill
- tanstack-formSkill
- tanstack-routerSkill
- flutter-clean-arch-getxSkill
- flutter-flavorsSkill
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 18 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Always define query keys as a factory object in the feature's constants file — never inline ad-hoc array keys.
- Distinctive: line 22
Always define query keys as a factory object in the feature's constants file.
- Very specific: line 218
After create: invalidate lists()
- Very specific: line 219
After update: invalidate both lists() and detail(id)
- Very specific: line 220
After delete: invalidate lists()
“Common” is measured: kept by at least 6 in 10 of the 18 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Data Fetching with TanStack Query
Core Invariants (always enforced — never violate)
- Always define query keys as a factory object in the feature's constants file — never inline ad-hoc array keys.
Query Client Config
The global QueryClient is configured in @/core/config/query-client.config:
staleTime: 5 minutes— data stays fresh for 5 min before refetchgcTime: 10 minutes— unused cache cleared after 10 minretry: 1— one retry on failurerefetchOnWindowFocus: false
Query Keys
Always define query keys as a factory object in the feature's constants file. This makes invalidation precise.
// constants/your-feature.constants.ts
import type { YourFeatureFilterParams } from '../types'
export const YOUR_FEATURE_QUERY_KEYS = {
all: ['your-features'] as const,
lists: () => [...YOUR_FEATURE_QUERY_KEYS.all, 'list'] as const,
list: (params: YourFeatureFilterParams) => [...YOUR_FEATURE_QUERY_KEYS.lists(), params] as const,
details: () => [...YOUR_FEATURE_QUERY_KEYS.all, 'detail'] as const,
detail: (id: number) => [...YOUR_FEATURE_QUERY_KEYS.details(), id] as const,
}List Query
// hooks/useYourFeatures.ts
import { useQuery } from '@tanstack/react-query'
import { YOUR_FEATURE_QUERY_KEYS } from '../constants'
import { yourFeatureService } from '../services'
import type { YourFeatureFilterParams } from '../types'
export function useYourFeatures(params?: YourFeatureFilterParams) {
return useQuery({
queryKey: YOUR_FEATURE_QUERY_KEYS.list(params || {}),
queryFn: ({ signal }) => yourFeatureService.getAll(params, signal),
staleTime: 5 * 60 * 1000,
})
}Single Item Query
// hooks/useYourFeature.ts
import { useQuery } from '@tanstack/react-query'
import { YOUR_FEATURE_QUERY_KEYS } from '../constants'
import { yourFeatureService } from '../services'
export function useYourFeature(id: number) {
return useQuery({
queryKey: YOUR_FEATURE_QUERY_KEYS.detail(id),
queryFn: ({ signal }) => yourFeatureService.getById(id, signal),
staleTime: 5 * 60 * 1000,
enabled: !!id,
})
}Create Mutation
// hooks/useCreateYourFeature.ts
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { YOUR_FEATURE_QUERY_KEYS } from '../constants'
import { yourFeatureService } from '../services'
import type { YourFeatureCreateRequest } from '../types'
export function useCreateYourFeature() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (data: YourFeatureCreateRequest) => yourFeatureService.create(data),
onSuccess: () => {
// Invalidate the list so it refetches
queryClient.invalidateQueries({ queryKey: YOUR_FEATURE_QUERY_KEYS.lists() })
},
})
}Update Mutation
// hooks/useUpdateYourFeature.ts
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { YOUR_FEATURE_QUERY_KEYS } from '../constants'
import { yourFeatureService } from '../services'
import type { YourFeatureUpdateRequest } from '../types'
export function useUpdateYourFeature(id: number) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (data: YourFeatureUpdateRequest) => yourFeatureService.update(id, data),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: YOUR_FEATURE_QUERY_KEYS.lists() })
queryClient.invalidateQueries({ queryKey: YOUR_FEATURE_QUERY_KEYS.detail(id) })
},
})
}Delete Mutation
// hooks/useDeleteYourFeature.ts
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { YOUR_FEATURE_QUERY_KEYS } from '../constants'
import { yourFeatureService } from '../services'
export function useDeleteYourFeature() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (id: number) => yourFeatureService.delete(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: YOUR_FEATURE_QUERY_KEYS.lists() })
},
})
}Service Layer Pattern
Each feature has a service object in services/your-feature.service.ts. The service handles Axios calls; hooks handle caching.
import axiosInstance from '@/core/api/axios.config'
import { YOUR_FEATURE_ENDPOINTS } from '../constants'
import type { YourFeaturesResponse, YourFeatureDetailResponse, YourFeatureCreateRequest } from '../types'
export const yourFeatureService = {
async getAll(params?: YourFeatureFilterParams, signal?: AbortSignal): Promise<YourFeaturesResponse> {
const { data } = await axiosInstance.get<YourFeaturesResponse>(
YOUR_FEATURE_ENDPOINTS.BASE, { params, signal }
)
return data
},
async getById(id: number, signal?: AbortSignal): Promise<YourFeatureDetailResponse> {
const { data } = await axiosInstance.get<YourFeatureDetailResponse>(
YOUR_FEATURE_ENDPOINTS.DETAIL(id), { signal }
)
return data
},
async create(payload: YourFeatureCreateRequest, signal?: AbortSignal) {
const { data } = await axiosInstance.post(YOUR_FEATURE_ENDPOINTS.BASE, payload, { signal })
return data
},
async update(id: number, payload: YourFeatureUpdateRequest, signal?: AbortSignal) {
const { data } = await axiosInstance.put(YOUR_FEATURE_ENDPOINTS.UPDATE(id), payload, { signal })
return data
},
async delete(id: number, signal?: AbortSignal) {
const { data } = await axiosInstance.delete(YOUR_FEATURE_ENDPOINTS.DETAIL(id), { signal })
return data
},
}Using Mutations in Components
const createMutation = useCreateYourFeature()
// In form onSubmit or button handler:
createMutation.mutate(formData, {
onSuccess: () => {
showSuccess(t('feature.createSuccess'))
navigate({ to: '/feature' })
},
onError: (error) => {
showError(translateError(error))
},
})
// Check pending state for loading UI:
<Button disabled={createMutation.isPending}>
{createMutation.isPending ? t('common.saving') : t('common.save')}
</Button>Route Loader Prefetch
For detail pages, prefetch in the route loader so data is ready before the component renders:
// routes/_layout/section/feature/$featureId/index.tsx
loader: async ({ params, context }) => {
await context.queryClient.ensureQueryData({
queryKey: YOUR_FEATURE_QUERY_KEYS.detail(Number(params.featureId)),
queryFn: ({ signal }) => yourFeatureService.getById(Number(params.featureId), signal),
})
},The component's useYourFeature(id) call then hits the cache immediately.
Cache Invalidation Strategy
- After create: invalidate
lists() - After update: invalidate both
lists()anddetail(id) - After delete: invalidate
lists() - For granular invalidation, pass
exact: trueor specific query keys
// Invalidate all lists (any params)
queryClient.invalidateQueries({ queryKey: YOUR_FEATURE_QUERY_KEYS.lists() })
// Invalidate exact detail
queryClient.invalidateQueries({ queryKey: YOUR_FEATURE_QUERY_KEYS.detail(id) })
// Invalidate everything for this feature
queryClient.invalidateQueries({ queryKey: YOUR_FEATURE_QUERY_KEYS.all })Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

