zustand-store-ts
它能做什么
这段代码帮你使用 Zustand 库为网页应用创建数据“store”(状态仓库)。它负责组织数据的保存方式,以及如何访问和修改这些数据,并确保一切与 TypeScript 配合正常工作。
适用场景
- ✓需要保存许多部分都会用到的信息时。
- ✓为项目搭建状态管理系统时。
- ✓组织随时间变化的全局数据时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/zustand-store-ts/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“创建一个用于管理购物车状态的 store,包括商品和总价,并提供添加和删除商品的函数。”
每周 5 个新技能,1 分钟读完。
工作原理
它采用一种模式,分别定义要保存什么(状态)以及如何处理这些数据(操作)。它还能确保数据变化时,只有应用中需要更新的部分会重新渲染。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Zustand Store
Create Zustand stores following established patterns with proper TypeScript types and middleware.
Quick Start
Copy the template from assets/template.ts and replace placeholders:
{{StoreName}}→ PascalCase store name (e.g.,Project){{description}}→ Brief description for JSDoc
Always Use subscribeWithSelector
import { create } from 'zustand';
import { subscribeWithSelector } from 'zustand/middleware';
export const useMyStore = create<MyStore>()(
subscribeWithSelector((set, get) => ({
// state and actions
}))
);
Separate State and Actions
export interface MyState {
items: Item[];
isLoading: boolean;
}
export interface MyActions {
addItem: (item: Item) => void;
loadItems: () => Promise<void>;
}
export type MyStore = MyState & MyActions;
Use Individual Selectors
// Good - only re-renders when `items` changes
const items = useMyStore((state) => state.items);
// Avoid - re-renders on any state change
const { items, isLoading } = useMyStore();
Subscribe Outside React
useMyStore.subscribe(
(state) => state.selectedId,
(selectedId) => console.log('Selected:', selectedId)
);
Integration Steps
- Create store in
src/frontend/src/store/ - Export from
src/frontend/src/store/index.ts - Add tests in
src/frontend/src/store/*.test.ts
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题
什么是 Zustand?
Zustand 是一个让网页应用中的数据管理变得更简单的库。
什么是 TypeScript?
TypeScript 是一种编程语言,它增加了额外的检查,帮助你避免代码中的错误。
什么是中间件?
中间件就像为 store 添加额外功能的“插件”,比如记录数据变化的日志,或处理异步操作。
详情
作者的原始描述
Create Zustand stores following established patterns with proper TypeScript types and middleware.
热度
- GitHub 星标
- 48k
- 排名
- #6244
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。