一键导入
tanstack-query
TanStack Query v5 patterns for data fetching, mutations, and cache management. Use when writing queries, mutations, or working with server state.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
TanStack Query v5 patterns for data fetching, mutations, and cache management. Use when writing queries, mutations, or working with server state.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Reproduce a research paper / white paper / arXiv result as a Tangle pipeline. Use when the user asks to "reproduce", "replicate", or "implement" a paper, benchmark, or arXiv link as an experiment.
Drive the open-source Tangle CLI (`tangle-cli`) via Bash for local pipeline/component workflows and API-backed run submission, status, logs, and artifacts. Use whenever an agent needs to validate, hydrate, submit, inspect, or debug Tangle pipelines and runs from the command line.
Answer Tangle product, docs, and how-to questions from a local RAG over the TangleML documentation. Use for conceptual / "what is" / "how do I" lookups, not live run or execution data.
TanStack Router patterns for routing, navigation, search params, and layouts. Use when creating routes, navigating, or working with URL state.
Comprehensive Reveal.js reference for building HTML slide decks. Use whenever the user wants to create, revise, or extend a presentation, slide deck, or talk — especially from Markdown — including transitions, Auto-Animate, Mermaid diagrams, animatable SVG, video, backgrounds, fragments, code highlighting, speaker notes, math, themes, configuration, and PDF export.
Gather, vet, and cite sources for a research question. Use when answering factual questions, comparing options, or producing an evidence-backed write-up.
| name | tanstack-query |
| description | TanStack Query v5 patterns for data fetching, mutations, and cache management. Use when writing queries, mutations, or working with server state. |
This project uses TanStack Query v5 (@tanstack/react-query) for all server state. The shared
QueryClient lives at @/shared/api/queryClient and is provided in
apps/web/src/routes/providers/AppProviders.tsx.
Prefer useQuery hooks over Context providers for server state. Only reach for a Context
provider when you need to share non-query app-wide state (theme, live session status). Wrapping query
results in Context bypasses the query cache and causes unnecessary re-renders.
Each feature owns its data layer:
fetch + parse): features/<feature>/api/<feature>Api.tsfeatures/<feature>/hooks/use*.tsfeatures/<feature>/model/<feature>QueryKeys.tsAPI functions build URLs with apiUrl from @/shared/lib/basePath (so requests resolve behind the
proxy mount-prefix) and parse into shared types from @tangent/shared/contracts:
import type {
AgentBundleMeta,
ListAgentBundlesResponse,
} from "@tangent/shared/contracts";
import { apiUrl } from "@/shared/lib/basePath";
export async function listAgentBundles(): Promise<AgentBundleMeta[]> {
const res = await fetch(apiUrl("/api/agent-bundles"));
if (!res.ok) throw new Error(`Request failed with status ${res.status}`);
const data = (await res.json()) as ListAgentBundlesResponse;
return data.bundles;
}
Use hierarchical, array-based keys via a per-feature factory object:
// features/agent-bundles/model/agentBundleQueryKeys.ts
export const AgentBundleQueryKeys = {
All: () => ["agent-bundles"] as const,
Id: (id: string) => ["agent-bundles", id] as const,
} as const;
Define queries inline in custom hooks — this project does not use the queryOptions helper:
import { useQuery } from "@tanstack/react-query";
import { listAgentBundles } from "@/features/agent-bundles/api/agentBundlesApi";
import { AgentBundleQueryKeys } from "@/features/agent-bundles/model/agentBundleQueryKeys";
export function useAgentBundles() {
return useQuery({
queryKey: AgentBundleQueryKeys.All(),
queryFn: listAgentBundles,
});
}
Set staleTime to match data volatility, and use enabled for dependent queries:
return useQuery({
queryKey: AgentBundleQueryKeys.Id(id),
queryFn: () => getAgentBundle(id),
enabled: !!id,
staleTime: 5 * 60 * 1000,
});
Invalidate the relevant keys on success and let the queries refetch. This project uses
post-mutation invalidation, not optimistic updates — don't use setQueryData to fake results.
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { deleteAgentBundle } from "@/features/agent-bundles/api/agentBundlesApi";
import { AgentBundleQueryKeys } from "@/features/agent-bundles/model/agentBundleQueryKeys";
export function useDeleteAgentBundle() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: deleteAgentBundle,
onSuccess: () => {
void queryClient.invalidateQueries({
queryKey: AgentBundleQueryKeys.All(),
});
},
});
}
Multiple invalidations in one onSuccess are fine. There is no global toast/notify utility —
surface mutation failures through the component's isError/error state (or an error boundary),
not a notify() call.
queryClient.invalidateQueries() — primary cache invalidationqueryClient.getQueryData() — read cache without refetchingqueryClient.ensureQueryData() — fetch-if-not-cached for dependent/recursive dataUse a function for refetchInterval to stop polling once work is complete:
refetchInterval: (query) => {
const status = query.state.data?.status;
return status === "RUNNING" ? 5000 : false;
},
Some state is pushed, not polled. Session chat/status uses socket.io-client (see
features/chat/hooks/useSessionChat.ts and features/sessions/components/SessionStatusProvider.tsx)
rather than a polling query. Use a query for request/response data; use the socket for streaming
updates.