← 返回 Skills 市场
Data Fetching
作者
Bovin Phang
· GitHub ↗
· v2.5.0
· MIT-0
29
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install fec-data-fetching
功能描述
Manage server-state fetching with TanStack Query using typed queries, caching, invalidation, mutations, optimistic updates, infinite queries, prefetch, and S...
使用说明 (SKILL.md)
TanStack Query 数据获取
Purpose
用声明式 server state 管理替代手写 useEffect + loading。
Procedure
- 判断状态来源:来自服务端且需要缓存、去重、刷新、分页或 mutation 时使用 TanStack Query;纯本地 UI 状态用
useState/store。 - 建立
QueryClientProvider,按业务数据新鲜度设置staleTime、gcTime、retry 和窗口聚焦刷新。 - 设计稳定 query key:数组结构包含实体、动作和所有影响结果的参数。
- API 函数保持纯请求函数,Query hook 负责缓存、select、loading/error/empty 状态。
- mutation 成功后 invalidation;需要即时反馈时使用 optimistic update 并在
onError回滚。
Quick Start
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
export function UserList({ keyword }: { keyword: string }) {
const query = useQuery({
queryKey: ["users", "list", { keyword }],
queryFn: () => getUserList({ keyword, page: 1, pageSize: 20 }),
select: (response) => response.list,
});
if (query.isLoading) return \x3CSkeleton />;
if (query.isError) return \x3CErrorFallback onRetry={() => query.refetch()} />;
if (!query.data?.length) return \x3CEmptyState />;
return query.data.map((user) => \x3CUserRow key={user.id} user={user} />);
}
export function useCreateUser() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: createUser,
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["users"] }),
});
}
Detailed References
涉及 QueryClient 默认配置、乐观更新、无限滚动查询、预取、SSR 水合和 API 层整合时,加载 references/query-patterns.md。
Constraints
- 相同数据必须复用相同 query key;参数缺失会造成缓存串读。
staleTime过长会显示旧数据,过短会造成频繁请求。- TanStack Query 不管理本地 UI 状态;不要把 modal、输入框值放进 query cache。
- 乐观更新必须保存快照并在
onError回滚。 - Next.js App Router SSR 需要
dehydrate/HydrationBoundary。
Expected Output
数据获取层具备 loading/error/empty/data 状态,重复请求自动去重,mutation 后缓存正确失效或回滚,API 层与 UI 层边界清晰。
安全使用建议
This skill is appropriate to install if you want React Query/TanStack Query implementation guidance. It may influence how an agent writes application data-fetching code, including cache invalidation and optimistic updates, so review generated changes for product-specific API behavior and rollback correctness.
能力评估
Purpose & Capability
The artifacts coherently describe implementing and reviewing server-state data fetching with TanStack Query, including query keys, caching, mutations, optimistic updates, infinite queries, prefetching, SSR hydration, and API-layer boundaries.
Instruction Scope
Instructions are scoped to frontend implementation guidance and explicitly exclude local UI state and Service Worker caching; no prompt override, hidden role change, or unrelated agent instruction was found.
Install Mechanism
The package contains SKILL.md, README, metadata, and one reference document; package.json declares no dependencies, lifecycle scripts, executables, or automatic install-time behavior.
Credentials
The skill only provides code examples and design guidance for application code; it does not require filesystem scanning, network credentials, local profiles, secrets, or privileged environment access.
Persistence & Privilege
No background workers, cron jobs, privilege escalation, credential/session handling, or persistence mechanisms are present; cache lifetime examples are normal TanStack Query application behavior.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install fec-data-fetching - 安装完成后,直接呼叫该 Skill 的名称或使用
/fec-data-fetching触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v2.5.0
Version 2.5.0
- Added comprehensive documentation in SKILL.md for implementing and reviewing TanStack Query/React Query server-state flows, including typed queries, caching, invalidation, mutations, and SSR hydration.
- Included detailed usage guidelines, best practices, and a quick start code example.
- Clarified boundaries between server state management and local UI state.
- Outlined key constraints and edge cases for robust query and mutation handling.
元数据
常见问题
Data Fetching 是什么?
Manage server-state fetching with TanStack Query using typed queries, caching, invalidation, mutations, optimistic updates, infinite queries, prefetch, and S... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 29 次。
如何安装 Data Fetching?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install fec-data-fetching」即可一键安装,无需额外配置。
Data Fetching 是免费的吗?
是的,Data Fetching 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Data Fetching 支持哪些平台?
Data Fetching 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Data Fetching?
由 Bovin Phang(@bovinphang)开发并维护,当前版本 v2.5.0。
推荐 Skills