← Back to Skills Marketplace
bovinphang

Data Fetching

by Bovin Phang · GitHub ↗ · v2.5.0 · MIT-0
cross-platform ✓ Security Clean
29
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install fec-data-fetching
Description
Manage server-state fetching with TanStack Query using typed queries, caching, invalidation, mutations, optimistic updates, infinite queries, prefetch, and S...
README (SKILL.md)

TanStack Query 数据获取

Purpose

用声明式 server state 管理替代手写 useEffect + loading

Procedure

  1. 判断状态来源:来自服务端且需要缓存、去重、刷新、分页或 mutation 时使用 TanStack Query;纯本地 UI 状态用 useState/store。
  2. 建立 QueryClientProvider,按业务数据新鲜度设置 staleTimegcTime、retry 和窗口聚焦刷新。
  3. 设计稳定 query key:数组结构包含实体、动作和所有影响结果的参数。
  4. API 函数保持纯请求函数,Query hook 负责缓存、select、loading/error/empty 状态。
  5. 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 层边界清晰。

Usage Guidance
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.
Capability Assessment
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.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install fec-data-fetching
  3. After installation, invoke the skill by name or use /fec-data-fetching
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
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.
Metadata
Slug fec-data-fetching
Version 2.5.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Data Fetching?

Manage server-state fetching with TanStack Query using typed queries, caching, invalidation, mutations, optimistic updates, infinite queries, prefetch, and S... It is an AI Agent Skill for Claude Code / OpenClaw, with 29 downloads so far.

How do I install Data Fetching?

Run "/install fec-data-fetching" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Data Fetching free?

Yes, Data Fetching is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Data Fetching support?

Data Fetching is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Data Fetching?

It is built and maintained by Bovin Phang (@bovinphang); the current version is v2.5.0.

💬 Comments