金色时刻 · 15:48
让好资源,触手可及
AGENT SKILL

state-management

state-management 是面向软件开发的 Agent Skill,来自 HoangNguyen0403/agent-skills-standard。查看技能说明、操作步骤与使用约定,并通过原项目了解详细用法。

Standards for managing local, global, and server state.

SKILL.md

下载 MD ↓
nameReact State Management
descriptionStandards for managing local, global, and server state.
metadata{"labels": ["react", "state", "redux", "zustand", "context"], "triggers": {"files": ["**/*.tsx", "**/*.jsx"], "keywords": ["state", "useReducer", "context", "store", "props"]}}

React State Management

Priority: P0 (CRITICAL)

Choosing the right tool for state scope.

Implementation Guidelines

  • Local: useState. useReducer if complex (state machine).
  • Derived: const fullName = first + last. No state sync.
  • Context: DI, Theming, Auth. Not for high-freq data.
  • Global: Zustand/Redux for app-wide complex flow.
  • Server Cache: Use React.cache (RSC) to dedupe requests per render.
  • Server State: React Query / SWR / Apollo. Cache != UI State.
  • URL: Store filter/sort params in URL (Source of Truth).
  • Immutability: Never mutate. Use spread or Immer.

Anti-Patterns

  • No Prop Drilling > 2: Use Context/Composition.
  • No Mirroring Refs: Don't copy props to state.
  • No Multi-Source: Single Source of Truth.
  • No Context Abuse: Context causes full-tree re-render.

Reference & Examples

For Zustand, Redux Toolkit, and TanStack Query patterns: See references/REFERENCE.md.

Related Topics

hooks | component-patterns | performance

来源:HoangNguyen0403/agent-skills-standard · MIT 许可 · 许可原文 · MD 为来源页保存的历史版本