用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/NTQ78/Todo-app --skill frontend-tanstack-store命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Use when deploying Cloudflare Workers, managing R2 storage, or working with Cloudflare infrastructure
Use when working with ANTD components, theme tokens, icons, forms, or feedback components (message/notification/modal)
Use when adding, referencing, or serving static assets (images, fonts, videos, 3D models) through the R2 CDN pipeline with type-safe imports
正在显示 SKILL.md
基于 SOC 职业分类
| name | frontend-tanstack-store |
| description | Use when creating or modifying TanStack Store for global state management |
Global state management using @tanstack/react-store with granular selectors.
frontend-provider-context)import { Store, useStore, shallow } from "@tanstack/react-store";
// 1. State class with defaults
class State_App {
theme: "light" | "dark" = "light";
sidebarCollapsed: boolean = false;
notifications: string[] = [];
}
// 2. Store instance
export const Store_App = new Store(new State_App());
// 3. Selectors - one per key (granular subscriptions)
export const useStore_App_Theme = () => useStore(Store_App, (s) => s.theme);
export const useStore_App_SidebarCollapsed = () => useStore(Store_App, (s) => s.sidebarCollapsed);
export const useStore_App_Notifications = () =>
useStore(Store_App, (s) => s.notifications, { equal: shallow });
// 4. Actions
export const Store_App_Actions = {
overwrite: (partial: Partial<State_App>) => Store_App.setState((s) => ({ ...s, ...partial })),
notifications: {
add: (msg: string) =>
Store_App.setState((s) => ({ ...s, notifications: [...s.notifications, msg] })),
remove: (msg: string) =>
Store_App.setState((s) => ({
...s,
notifications: s.notifications.filter((n) => n !== msg),
})),
clear: () => Store_App.setState((s) => ({ ...s, notifications: [] })),
},
};
| Entity | Pattern | Example |
|---|---|---|
| State class | State_[Name] | State_App, State_Editor |
| Store | Store_[Name] | Store_App |
| Selector hook | useStore_[Name]_[Key] | useStore_App_Theme |
| Actions | Store_[Name]_Actions | Store_App_Actions |
| File | Store_[Name].ts | src/stores/Store_App.ts |
// Read (granular - only re-renders when this value changes)
const theme = useStore_App_Theme();
const notifications = useStore_App_Notifications();
// Write - simple values via overwrite
Store_App_Actions.overwrite({ theme: "dark" });
Store_App_Actions.overwrite({ theme: "dark", sidebarCollapsed: true });
// Write - complex operations via nested handlers
Store_App_Actions.notifications.add("New message");
Store_App_Actions.notifications.clear();
| State Type | Selector Pattern |
|---|---|
| Primitives | useStore(store, (s) => s.key) |
| Arrays/Objects | useStore(store, (s) => s.key, { equal: shallow }) |
MUST use shallow for arrays/objects to prevent re-renders when reference changes but contents are equal.
| Scenario | Use |
|---|---|
| Simple value updates | overwrite({ key: value }) |
| Multiple keys at once | overwrite({ key1: v1, key2: v2 }) |
| Array mutations | Nested handler: key.add(), key.remove(), key.clear() |
| Boolean toggle | Nested handler: key.toggle() |
| Computed updates | Nested handler with logic |
Nested handler naming:
| Type | Handlers |
|---|---|
| Arrays | add, remove, clear, set |
| Booleans | toggle, set |
| Objects | update, set, clear |
| Wrong | Correct |
|---|---|
useStore(store, (s) => s) (subscribe to all) | useStore(store, (s) => s.specificKey) |
Array selector without shallow | useStore(store, (s) => s.arr, { equal: shallow }) |
Direct Store.setState() in components | Use Store_Actions.overwrite() |
| Nested state objects | Keep state flat |
| Individual setter per key | Use overwrite() for simple keys |