用途:按既定模式创建 Zustand store,使用恰当的 TypeScript 类型与中间件,适合构建 React 状态管理、创建 store 的场景。
主要能力与约定:始终使用 subscribeWithSelector 中间件;状态与操作分离,分别定义 State 与 Actions 接口再合并为 Store 类型;在组件中使用单独 selector 以避免多余重渲染;支持在 React 之外通过 subscribe 订阅状态变化。
使用方式:从 assets/template.ts 复制模板并替换占位符,包括 {{StoreName}}(PascalCase 的 store 名称,如 Project)和 {{description}}(用于 JSDoc 的简短描述)。store 创建示例:export const useMyStore = create()(subscribeWithSelector((set, get) => ({ /* state and actions / })));。类型定义示例:export interface MyState、export interface MyActions,再以 export type MyStore = MyState & MyActions 合并。单独 selector 用法:const items = useMyStore((state) => state.items);,避免使用 const { items, isLoading } = useMyStore();。React 外订阅:useMyStore.subscribe((state) => state.selectedId, (selectedId) => console.log('Selected:', selectedId));。集成步骤:在 src/frontend/src/store/ 中创建 store;从 src/frontend/src/store/index.ts 导出;在 src/frontend/src/store/.test.ts 添加测试。
限制:资料未提供更多边界条件、依赖版本或收费信息。