一键导入
tanstack-query
TanStack Query patterns, data fetching, cache invalidation, route loaders. Load when working with server state, queries, mutations.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
TanStack Query patterns, data fetching, cache invalidation, route loaders. Load when working with server state, queries, mutations.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Project UI design system — read this before building any page or component. Defines visual style, color tokens, typography, and constraints.
Design tokens, Tailwind classes, card patterns, spacing, colors, radius, typography, gamification patterns (Duolingo). Load when working on UI, components, styling.
Phân tích và refactor codebase. Load khi cần review code structure, tìm vấn đề thiết kế, tách component, dọn dead code.
Tạo, cập nhật, hoặc implement RFC cho frontend-v2. Use when user says 'tạo rfc', 'viết rfc', 'implement rfc', 'update rfc', 'rfc status', or when a cross-cutting UI/UX change needs formal spec before coding.
TypeScript patterns, type conventions, naming, code style. Load when writing complex types, reviewing code style, or refactoring.
UI component rules: type safety, props, styling, tokens, icons, context providers. Load when creating or styling components.
基于 SOC 职业分类
| name | tanstack-query |
| description | TanStack Query patterns, data fetching, cache invalidation, route loaders. Load when working with server state, queries, mutations. |
Không fetch trong useEffect. Dùng TanStack Query hoặc route loader. Effect-based fetch tạo race condition, waterfall, double-fetch dưới StrictMode.
Không useState để mirror server data. Server state là quyền của TanStack Query.
Query viết dưới dạng queryOptions factory. Định nghĩa một lần, dùng ở cả loader (ensureQueryData) và component (useSuspenseQuery). Không gọi queryClient trực tiếp trong component.
Query key theo factory pattern. Mỗi resource có một object key: { all, list(params), detail(id) }. Đây là nguồn duy nhất của key. Invalidate luôn qua factory.
staleTime khai báo một lần trong queryOptions factory. Không override per-call.
URL là nguồn của query state. Filter, pagination, sort, selected tab đặt trong search params. Search params phải có validateSearch schema. Query key derive từ URL.
4 trạng thái phải design đủ. Loading, error, empty, success. Loading/error do Suspense + ErrorBoundary ở route. Empty/success do component tự xử.
Mutation invalidate bằng key, không setState tay. onSuccess: () => queryClient.invalidateQueries({ queryKey: keys.list() }).
// lib/queries/example.ts
export const exampleQueryOptions = (id: string) =>
queryOptions({
queryKey: ["example", id],
queryFn: () => mockFetchExample(id),
staleTime: 5 * 60 * 1000,
})
// route file
export const Route = createFileRoute("/_app/example/$id")({
loader: ({ context: { queryClient }, params }) =>
queryClient.ensureQueryData(exampleQueryOptions(params.id)),
component: ExamplePage,
})
// component
function ExamplePage() {
const { id } = Route.useParams()
const { data } = useSuspenseQuery(exampleQueryOptions(id))
// ...
}
Every mock function that will be replaced by API must have:
// TODO(backend): GET /api/examples/:id
// Response: { id, title, items: ExampleItem[] }