.cursor/skills/tanstack-query-v5/SKILL.md
TanStack Query (React Query) for async operations, data fetching, caching, and state management. Use when: fetching server data, managing async operations, caching responses, handling mutations, or any operation that benefits from automatic state management and caching.
npx skillsauth add blockmatic-icebox/basilic-old tanstack-queryInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
@lukemorales/query-key-factory for query key managementisLoading, error, or isError states (provided by hooks)queryFn can be any Promise-returning function (not just HTTP calls)@lukemorales/query-key-factory) for all query keysqueryClient.invalidateQueries({ queryKey: users._def })useQuery<ResponseType>(...)useQuery({ queryKey: ['users', id] })queryClient.invalidateQueries({ queryKey: ['users'] })Centralized, type-safe query keys:
import { createQueryKeys } from '@lukemorales/query-key-factory'
export const users = createQueryKeys('users', {
detail: (id: string) => ({
queryKey: [id],
queryFn: () => fetchUser(id),
}),
list: (filters?: Filters) => ({
queryKey: [filters],
queryFn: () => fetchUsers(filters),
}),
})
// Usage
import { useQuery } from '@tanstack/react-query'
import { users } from '@/queries/users'
const { data, isLoading, error } = useQuery(users.detail(userId))
File Organization: src/queries/users.ts - Query key factory for users, src/queries/articles.ts - Query key factory for articles, src/queries/index.ts - Re-export all query keys
TanStack Query accepts ANY async queryFn—not just HTTP calls:
// Server data fetching (traditional)
const { data } = useQuery({
queryKey: ['users', userId],
queryFn: () => fetchUser(userId),
})
// Local computation (no network)
const { data } = useQuery({
queryKey: ['fibonacci', n],
queryFn: () => computeFibonacci(n),
})
// localStorage read
const { data: settings } = useQuery({
queryKey: ['user-settings'],
queryFn: () => Promise.resolve(
JSON.parse(localStorage.getItem('settings') || '{}')
),
})
// File operation
const { data } = useQuery({
queryKey: ['file-content', path],
queryFn: () => readFile(path),
})
When to use: Any async operation that benefits from automatic caching, stale management, or repeated execution
When NOT to use: One-off promises without caching needs (use plain async/await in event handlers)
Mutations with automatic invalidation:
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { users } from '@/queries/users'
function useCreateUser() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (data: CreateUserInput) => {
const response = await createUser(data)
return response
},
onSuccess: () => {
// Namespace invalidation (recommended)
queryClient.invalidateQueries({ queryKey: users._def })
},
})
}
// Usage
const createUser = useCreateUser()
createUser.mutate({ name: 'John', email: '[email protected]' })
Pagination with infinite scroll:
import { useInfiniteQuery } from '@tanstack/react-query'
import { users } from '@/queries/users'
const {
data,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
} = useInfiniteQuery({
queryKey: ['users', 'infinite'],
queryFn: ({ pageParam = 0 }) => fetchUsers({ page: pageParam }),
getNextPageParam: (lastPage, pages) => lastPage.nextPage,
initialPageParam: 0,
})
Configure defaults at provider level:
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { useState } from 'react'
function Providers({ children }: { children: ReactNode }) {
const [queryClient] = useState(() => new QueryClient({
defaultOptions: {
queries: {
staleTime: 60 * 1000, // 1 minute
retry: 1,
refetchOnWindowFocus: false,
},
},
}))
return (
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
)
}
Use generated hooks from OpenAPI specs:
import { useHealthCheck } from '@repo/react'
function HealthStatus() {
const { data, isLoading, error } = useHealthCheck()
if (isLoading) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
return <div>Status: {data.status}</div>
}
Extract query logic into reusable hooks:
// hooks/useUser.ts
import { useQuery } from '@tanstack/react-query'
import { users } from '@/queries/users'
export function useUser(userId: string) {
return useQuery(users.detail(userId))
}
// Component usage
function UserProfile({ userId }: { userId: string }) {
const { data: user, isLoading, error } = useUser(userId)
// ...
}
nuqs (filters, search, tabs, pagination)ahooks.useSetState (form state, game engine, ephemeral UI)ahooks.useLocalStorageState (preferences, settings)useState (rare, prefer other options)Use TanStack Query for: Server data fetching, mutations, optimistic updates, background refetching, caching, any async operation that benefits from state management
Don't use TanStack Query for: URL-shareable state (use nuqs), grouped synchronous state (use ahooks.useSetState), one-off promises without caching needs
development
# Skill: wagmi ## Scope - React/Next.js wallet integration with Wagmi v3 for EVM chains - Contract interactions using viem v2 for address validation and transaction building - Transaction state management and error handling - Custom hooks wrapping wagmi for contract-specific interactions Does NOT cover: - Solana frontend development - Backend RPC interactions - Smart contract development ## Assumptions - Wagmi v3.3.2+ - viem v2.44.4 - React 18+ or Next.js 14+ - TypeScript v5+ with strict mo
development
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
development
Advanced TypeScript patterns for type-safe, maintainable code using sophisticated type system features. Use when building type-safe APIs, implementing complex domain models, or leveraging TypeScript's advanced type capabilities.
tools
# Skill: solidity ## Scope - Solidity 0.8.24 smart contract development with Foundry - EVM internals and execution environment understanding - Security patterns and vulnerability prevention - Gas optimization techniques - Testing strategies with Foundry (unit, fuzz, invariant) - Client interactions using viem v2 - OpenZeppelin Contracts integration Does NOT cover: - Frontend wallet integration (see wagmi skill) - Solana development (see solana skill) ## Assumptions - Solidity 0.8.24 - Found