1075551341/claude_code_config/state-management

Claude Code and agent skill by 1075551341/claude_code_config

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

管理前端状态、使用Redux/Pinia/Zustand、设计全局状态存储

Install

npx vskill@latest install 1075551341/claude_code_config/state-management

SKILL.md

The same SKILL.md was published earlier as 1075551341/claude_code_config/state-management.

状态管理最佳实践

描述

前端状态管理技能,涵盖 React(Zustand/Redux/Jotai)和 Vue(Pinia)的状态设计、 Store 拆分、异步状态处理、持久化和性能优化

触发条件

设计或实现前端状态管理方案时使用,包括全局状态、跨组件通信、缓存策略等场景

技术方案选型

场景推荐方案理由
React 轻量状态ZustandAPI 简洁,无 Provider,按需渲染
React 复杂状态Redux Toolkit中间件生态完整,DevTools 强大
React 原子状态Jotai细粒度更新,适合表单/编辑器
React 服务端状态TanStack Query缓存/重试/乐观更新一站式
Vue 状态管理PiniaVue 官方推荐,TypeScript 友好

Zustand 模板

typescript
import { create } from 'zustand'
import { devtools, persist } from 'zustand/middleware'
interface AppState {
count: number
loading: boolean
increment: () => void
fetchData: () => Promise<void>
}
export const useAppStore = create<AppState>()(
devtools(
persist(
(set, get) => ({
count: 0,
loading: false,
increment: () => set((state) => ({ count: state.count + 1 })),
fetchData: async () => {
set({ loading: true })
try {
const data = await api.getData()
set({ count: data.count, loading: false })
} catch {
set({ loading: false })
}
},
}),
{ name: 'app-storage' }
)
)
)

Pinia 模板

typescript
import { defineStore } from 'pinia'
export const useAppStore = defineStore('app', () => {
const count = ref(0)
const loading = ref(false)
const doubleCount = computed(() => count.value * 2)
async function fetchData() {
loading.value = true
try {
const data = await api.getData()
count.value = data.count
} finally {
loading.value = false
}
}
return { count, loading, doubleCount, fetchData }
})

最佳实践

  1. Store 拆分:按业务领域拆分(user/product/cart),禁止单一巨大 Store
  2. 选择器优化:使用 selector 精确订阅,避免不必要重渲染
  3. 异步状态:分离 loading/error/data 三态
  4. 持久化:仅持久化必要数据(Token/偏好),避免缓存过期数据
  5. 不可变更新:使用 Immer 或展开运算符,禁止直接修改 state

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/1075551341/claude_code_config/state-management/badge)](https://verified-skill.com/skills/1075551341/claude_code_config/state-management)

Something wrong with this skill or its page? Tell us.