data-fetching

Implement centralized data fetching with Service Layer, Zustand Store, and SWR hooks.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a robust architecture for managing data fetching in your application, moving away from inefficient useEffect hooks towards a more organized and performant pattern using Service Layers, Zustand stores, and SWR.

Core Features & Use Cases

  • Centralized Data Fetching: Encapsulates API calls within a dedicated Service Layer.
  • Optimized State Management: Leverages Zustand for client-side state and SWR for efficient data fetching, caching, and revalidation.
  • Optimistic Updates: Implements immediate UI feedback for mutations (create, update, delete) before server confirmation.
  • Use Case: When building a dashboard that displays a list of user profiles and allows for individual profile updates, this Skill ensures data is fetched efficiently, UI remains responsive during updates, and the data stays consistent.

Quick Start

Use the data-fetching skill to implement a new service for fetching user data and integrate it into the store using SWR hooks.

Frequently Asked Questions about data-fetching

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

FAQPage Schema
How do I manage data fetching efficiently without using useEffect in React?

You can manage data fetching without useEffect by implementing a Service Layer combined with Zustand and SWR, which centralizes API calls and handles component-level data management efficiently.

What is the best way to handle API integration and cache invalidation for client-side state?

The best way to handle API integration and cache invalidation is using a structured architecture with SWR for data fetching and revalidation, paired with Zustand for optimized client-side state management.

How do I implement optimistic updates for API mutations in a Zustand store?

Implement optimistic updates in a Zustand store by using SWR hooks within a Service Layer to provide immediate UI feedback during create, update, or delete mutations before server confirmation.

Can I use SWR with Zustand for centralized service layer API calls?

Yes, you can use SWR with Zustand to create a centralized Service Layer that encapsulates API calls, ensuring efficient data retrieval and deterministic data loading operations through structured hooks.

Why should I move my API calls into a dedicated service layer?

Moving API calls into a dedicated service layer solves problems related to inefficient data retrieval and manual cache invalidation, providing a robust architecture for data fetching and API interactions.

How do I set up a service for fetching user data with SWR and Zustand?

Set up a user data fetching service by creating dedicated service methods integrated into a Zustand store, using SWR hooks to manage data fetching, caching, and component-level data updates.