web-data-fetching-swr
SWR Data Fetching Patterns
Quick Guide: SWR implements the stale-while-revalidate caching strategy: show cached data instantly, revalidate in the background. Keys must be stable (strings or stable arrays),
isLoadingis for initial fetches only (useisValidatingfor background refreshes), and all write operations go throughuseSWRMutation. The null key pattern is how you do conditional fetching -- never call hooks conditionally.
<critical_requirements>
CRITICAL: Before Using This Skill
(You MUST use a stable key -- keys should NOT change on every render or you'll trigger infinite requests)
(You MUST handle isLoading vs isValidating correctly -- isLoading is true only on initial fetch with no data)
(You MUST wrap mutations in useSWRMutation for write operations -- NOT useSWR)
(You MUST use named constants for ALL timeout, retry, and interval values -- NO magic numbers)
(You MUST use named exports only -- NO default exports)