AGENT SKILL
frontend-state-management
暂无简介
使用场景前端开发
- License 许可
- MIT
- 最近更新
- 2026-11-06
- Stars
- ★ 8
- Forks
- 0
02 资源文件 1
- 参考文档evals.json735 B
03 SKILL.md 正文
frontend-state-management
The right state lives in exactly one place, and the test pins which boundary owns it.
What you do
Decide where each piece of state lives and how it is shaped, then wire it. The first call is always server-state vs client-state — they have different lifecycles and want different tools.
- Separate server-state (fetched, cacheable, can go stale) from client-state (UI, ephemeral). Don't hand-manage fetched data in a global store — let a query cache own it.
- Keep state local until two siblings need it; lift, then globalize, in that order — not the reverse.
- Choose by need: a query cache (React Query / SWR / TanStack Query) for server-state; a lightweight store (Zustand / Jotai / Pinia / Svelte stores) for shared client-state; Redux when its middleware and devtools discipline earn their weight.
- Normalize cached collections by id; read through memoized selectors so a change to one row doesn't re-render the list.
- Make cache invalidation explicit — keys, TTLs, and the mutations that trigger refetch.
Output shape
A state-shape decision plus wiring:
- State-shape decision — what's server-state, what's client-state, where each lives, and why.
- Store / query setup — the wiring (provider, store, query client) as code.
- Selectors — memoized accessors at the read sites.
- Invalidation plan — cache keys and when they refetch or reset.
- Test — pins the boundary (selector returns the derived value; cache invalidates on mutation).
Anti-patterns
- Server data hand-managed in a global store — you reinvent caching, worse than the library.
- Everything global — every component re-renders on every unrelated change.
- Unmemoized selectors returning fresh object refs — defeats the framework's bail-out.
- No invalidation story — stale data after mutations, or a refetch-the-world hammer.
- Prop-drilling five levels deep when a store or context is the honest answer.
- Derivable state stored and kept in sync by hand — two sources of truth, guaranteed drift.
Handoff
Return the state-shape decision and wiring to the invoking frontend specialist. The server contract behind the cache is backend-api-contract / backend-data-layer territory — this skill owns the client cache, not the source of truth. Component internals consuming the state chain into frontend-react. This skill does not dispatch.
04 同仓库更多 Skills
technical-writer-user-manual
暂无简介
★ 8
technical-writer-release-notes
暂无简介
★ 8
technical-writer-api-docs
暂无简介
★ 8
social-media-platform-post
暂无简介
★ 8
social-media-engagement-templates
暂无简介
★ 8
social-media-content-calendar
暂无简介
★ 8