首页/ AI 技能 / @skilllib/skill-2014279374336372738
Skill站外收录 @skilllib/skill-2014279374336372738

state-management

规范 React 应用中各类状态的管理方式,明确本地、派生、上下文、全局、服务端缓存及服务端数据的状态边界与技术选型,强调不可变更新、单一数据源和 URL 作为状态源等核心原则。

0.0 (0) 154 次安装 原作者 编程导航
收录于 2026-01-22
软件开发 AI 技能

Skills.MD

# 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](references/REFERENCE.md). ## Related Topics hooks | component-patterns | performance

评论 0

还没有评论,来抢沙发。