by sickn33
使用正确的 TypeScript 类型和中间件管理 React 状态很复杂。本技能提供经过验证的模式,用于创建可维护的 Zustand store,包含 subscribeWithSelector 和清晰的状态/操作分离。
1. 打开 Claude 聊天界面
2. 点击下方 "📋 复制" 按钮
3. 粘贴到 Claude 聊天框中并发送
4. 输入 "使用 zustand-store-ts 技能" 开始使用
=== zustand-store-ts 技能 === 作者: sickn33 描述: 使用正确的 TypeScript 类型和中间件管理 React 状态很复杂。本技能提供经过验证的模式,用于创建可维护的 Zustand store,包含 subscribeWithSelector 和清晰的状态/操作分离。 使用方法: 1. 调用技能: "使用 zustand-store-ts 技能" 2. 提供相关信息: 根据技能要求提供必要参数 3. 查看结果: 技能会返回处理结果 示例: "使用 zustand-store-ts 技能,帮我分析一下这段代码"
这种方法适用于所有 Claude 用户,不需要安装额外工具。
coding
safe
Create Zustand stores following established patterns with proper TypeScript types and middleware.
Copy the template from assets/template.ts and replace placeholders:
{{StoreName}} → PascalCase store name (e.g., Project){{description}} → Brief description for JSDocimport { create } from 'zustand';
import { subscribeWithSelector } from 'zustand/middleware';
export const useMyStore = create<MyStore>()(
subscribeWithSelector((set, get) => ({
// 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;
// Good - only re-renders when `items` changes
const items = useMyStore((state) => state.items);
// Avoid - re-renders on any state change
const { items, isLoading } = useMyStore();
useMyStore.subscribe(
(state) => state.selectedId,
(selectedId) => console.log('Selected:', selectedId)
);
src/frontend/src/store/src/frontend/src/store/index.tssrc/frontend/src/store/*.test.tsView Count
0
Download Count
0
Favorite Count
0
Quality Score
73