intermediate
Data fetching state
Model server-state caches through freshness, invalidation, optimistic updates, and background refetching.
Server-state libraries model remote data as a cache with explicit freshness rules — not as a manual Redux slice per endpoint. Concerns include keys, stale time, background refetch, mutations, invalidation, and optimistic UI.
Subtopics: TanStack Query, SWR, cache invalidation, optimistic UI.
On interviews: describe stale-while-revalidate; when to refetch on focus versus poll.
Common pitfalls: using fetch caches for UI toggles, missing invalidation after mutations, and ignoring error/retry semantics.
Checklist:
- Cache keys represent query identity.
- Separate loading metadata from domain slices.
- Invalidate or update after writes.
- Plan optimistic paths with rollback.