fec-data-fetching
Installation
SKILL.md
Server State data acquisition
Purpose
Establish clear data acquisition, caching, invalidation and submission boundaries for front-end server state to avoid request state being scattered among page components.
Procedure
- Determine the source of the state: use the request caching scheme when it comes from the server and needs caching, deduplication, refreshing, paging or mutation; use component state or store for purely local UI state.
- First use the existing data acquisition library of the project; when adding dependencies, you can consider TanStack Query for React/Vue/Solid/Svelte, or you can also use SWR, Nuxt/Nitro data acquisition or project encapsulation.
- Stable design cache key/query key: The structure contains entities, actions and all parameters that affect the results.
- The API function remains a pure request function, and the data hook/composable is responsible for cache, select, loading/error/empty status.
- Invalidation after mutation succeeds; use optimistic update when immediate feedback is needed and rollback when failure occurs.
React Quick Start
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";