state-management
Choose and implement state ownership, synchronization, subscriptions and mutation recovery in frontend applications.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-11
- Stars
- ★ 10
- Forks
- 1
01 前言 Front Matter
- name
- state-management
- description
- Choose and implement state ownership, synchronization, subscriptions and mutation recovery in frontend applications.
02 资源文件 4
- 参考文档EXAMPLES.md645 B
- 参考文档skill.yaml400 B
- 参考文档TROUBLESHOOTING.md325 B
- 参考文档VALIDATION.json336 B
03 SKILL.md 正文
state-management
Overview
Choose and implement state ownership, synchronization, subscriptions and mutation recovery in frontend applications. Match guidance to the actual task and project; this document does not implement an automatic enforcer.
When to Use
A state ownership, synchronization or update problem is in scope. Respect the existing React state/data stack rather than automatically introducing Zustand or TanStack Query.
Rules & Patterns
Identify authoritative state, derived values, URL state, transient UI state and server data. Keep each source of truth understandable and avoid unnecessary duplicate writable copies.
Use the project's existing data/cache utilities where suitable. Server data can be managed by a framework, query library or another deliberate architecture; it does not universally belong in one package.
Subscribe to the data actually needed and inspect rerender behavior before optimizing. Use selectors/equality APIs compatible with the installed version. A centralized key factory may help larger caches but is not required for every query.
Define invalidation, cancellation and stale-response behavior. When optimistic UI is appropriate, handle failed and overlapping mutations without restoring stale data over a newer successful change.
Scope caches and stores to the right user/request boundary. Shared client or server state must not leak identity or tenant-specific data across sessions.
Code Examples
For a filterable catalog, determine which filters belong in the URL, which state is local and which results come from the server. For optimistic editing, test overlapping updates and failure recovery rather than only a successful click.
See EXAMPLES.md for scoped scenarios and evidence boundaries.
Validation Checklist
- [ ] Exercise stale responses, relevant concurrency, invalidation and reset/session boundaries.
- [ ] Verify subscriptions and persisted effects at the appropriate layer.
Common Mistakes
Introducing a global store for a local toggle; forcing a specific library; restoring obsolete optimistic snapshots; using global server request state.
Integration Notes
Optional companion guidance: react, typescript, webapp-testing. Use it only when relevant and available; the skill does not install tools or authorize external actions.
04 同仓库更多 Skills
scoped-frontend
Frontend component design and React guidelines
scoped-backend
Backend service architecture and API endpoints
engineering-workflow
Core software engineering lifecycle workflow
team-auth
ContextOS skill for team-auth
claude
暂无简介
team-order
Team conventions for createOrder and item name normalization in src/order.ts.