data-fetching

Standardize server data fetching with SWR-backed Zustand stores and service layers.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/kingheu0818-sketch/lobehub_yu --skill data-fetching-kingheu0818-sketch
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-fetching
Source: https://github.com/kingheu0818-sketch/lobehub_yu/tree/main/.agents/skills/data-fetching
Command: npx skills add https://github.com/kingheu0818-sketch/lobehub_yu --skill data-fetching-kingheu0818-sketch

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It solves the chaos of inconsistent server data fetching by standardizing how components trigger requests, how APIs are called, and how cached results are stored and refreshed in Zustand.

Core Features & Use Cases

  • Service-layer API calls: centralizes all lambdaClient.query/mutate access behind typed service methods so components and stores stay clean.
  • Zustand store + SWR hooks: drives client fetching through useClientDataSWR hooks (instead of useEffect or useState for server data).
  • List vs detail caching patterns: supports array-based lists and map-based detail caching with refresh and optimistic update flows.
  • Mutation-safe refresh: enforces refreshXxx() patterns after write operations using lambdaClient.mutate and targeted cache invalidation.

Quick Start

Use the data-fetching skill to implement a new data slice that fetches a list and a detail entry using useFetchXxx SWR hooks, a domain service layer, and refreshXxx cache invalidation after mutations.

Frequently Asked Questions about data-fetching

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I standardize server data fetching with Zustand and SWR?

Standardize server data fetching by routing all reads through a typed service layer calling lambdaClient.query and driving client fetching with SWR-backed hooks stored in a Zustand store. This enforces consistent patterns for list and detail caching across your application.

What's the best way to migrate away from useEffect for fetching server data in a Zustand store?

Migrate away from useEffect by replacing request logic with useClientDataSWR hooks that fetch through a dedicated service layer. This moves server data caching into SWR and keeps the Zustand store clean by separating read operations from state management.

How do I implement optimistic updates and cache invalidation after mutations with SWR?

Implement optimistic updates by routing writes through lambdaClient.mutate and enforcing refreshXxx() patterns that target SWR cache keys. This mutation-safe refresh approach invalidates specific cache entries to ensure the UI reflects the latest server state without full reloads.

Can I use a service layer to centralize lambdaClient query and mutate calls?

Yes, you can centralize all lambdaClient.query and lambdaClient.mutate access behind typed service methods. This keeps components and Zustand stores clean by abstracting API interactions into a dedicated, reusable service layer.

How does list vs detail caching work with SWR hooks and Zustand?

List and detail caching use distinct patterns: array-based caching for list flows and map-based caching for detail entries. Both are managed through useFetchXxx SWR hooks and support targeted refresh helpers after write operations.

Why should I use SWR-backed hooks instead of useState for managing server data?

SWR-backed hooks provide built-in caching, revalidation, and mutation-safe refresh capabilities that useState cannot. By combining SWR with a Zustand store and service layer, you ensure consistent server data synchronization without manual effect-based request logic.