[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6QQAWFTG9AHZMYQ92NB6HVA":3,"skill-same:01M6QQAWFTG9AHZMYQ92NB6HVA":65},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":6,"ownerHtmlUrl":49,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":50,"install":51,"resources":64},"01M6QQAWFTG9AHZMYQ92NB6HVA","state-management",null,"Client-side state management with Zustand — global stores, selectors, useShallow, middleware (persist, devtools, immer) and the slices pattern. Use for shared UI state across components — filters, selections, sidebar\u002Fmodal state, shopping cart, undo history, drag state, multi-step wizard state, anything read or written by more than one component. Do NOT use for server data (use data-fetching) or URL-synced state (use useSearchParams from react-router). Load whenever a component needs state that isn't local to it.","SimaDevelopment\u002Fopsiforce","SimaDevelopment","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F153810655?v=4","01M6QQ054MKBDSS43AND3FNHDK","Opsima","01M6QQ058VFT6EY7HCBVN49G8Z",43,"AGPL-3.0","https:\u002F\u002Fgithub.com\u002FSimaDevelopment\u002Fopsiforce\u002Fblob\u002Fmain\u002Fagent-config\u002Fskills\u002Fstate-management\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"state management","state","management","persist","components","URL","middleware","shared","local","across","shopping","filters","router","read","zustand","wizard","server","devtools","component","react","2026-11-10 10:12:30",false,"---\nname: state-management\ndescription: Client-side state management with Zustand — global stores, selectors, useShallow, middleware (persist, devtools, immer) and the slices pattern. Use for shared UI state across components — filters, selections, sidebar\u002Fmodal state, shopping cart, undo history, drag state, multi-step wizard state, anything read or written by more than one component. Do NOT use for server data (use data-fetching) or URL-synced state (use useSearchParams from react-router). Load whenever a component needs state that isn't local to it.\n---\n\n# State Management\n\nZustand for client-side shared state, written against major v5. Already installed in the template (no `yarn add` needed).\n\n**Why Zustand:** zero boilerplate, no providers, ~1 KB, first-class TypeScript, selectors prevent unnecessary re-renders. For this template's app-builder workloads it's the right default; reach for `data-fetching` for server data and `useSearchParams` for URL-synced filters.\n\n## Quick start — TypeScript store\n\nUse `create\u003CT>()()` — double parentheses (see Issue #1 for why).\n\n```ts\nimport { create } from \"zustand\"\n\ninterface BearStore {\n  bears: number\n  increase: (by: number) => void\n}\n\nconst useBearStore = create\u003CBearStore>()((set) => ({\n  bears: 0,\n  increase: (by) => set((state) => ({ bears: state.bears + by })),\n}))\n```\n\n## Use in components\n\nAlways select the specific slice you need — this is what stops unnecessary re-renders:\n\n```tsx\nconst bears = useBearStore((state) => state.bears)        \u002F\u002F re-renders only when bears changes\nconst increase = useBearStore((state) => state.increase)  \u002F\u002F function reference is stable\n```\n\n## Core patterns\n\n**Counter store:**\n\n```ts\ninterface CounterStore { count: number; increment: () => void }\nconst useStore = create\u003CCounterStore>()((set) => ({\n  count: 0,\n  increment: () => set((state) => ({ count: state.count + 1 })),\n}))\n```\n\n**Persistent store — UI preferences only** (theme, collapsed panels, last tab). App data lives in the database through the backend (`web-app`), never in `persist`:\n\n```ts\nimport { persist, createJSONStorage } from \"zustand\u002Fmiddleware\"\n\nconst useStore = create\u003CUserPreferences>()(\n  persist(\n    (set) => ({\n      theme: \"system\",\n      setTheme: (theme) => set({ theme }),\n    }),\n    {\n      name: \"user-preferences\",\n      storage: createJSONStorage(() => localStorage),\n    },\n  ),\n)\n```\n\n## Critical rules\n\n**Always:**\n- Use `create\u003CT>()()` (double parentheses) in TypeScript (Issue #1)\n- Define separate interfaces for state and actions\n- Use selector functions to extract specific state slices\n- Use `set` with updater functions for derived state: `set((state) => ({ count: state.count + 1 }))`\n- Use unique `name` values for each persist-middleware store\n- Use `useShallow` when selecting multiple values into one object\n- Keep actions pure — no side effects beyond state updates\n\n**Never:**\n- Use `create\u003CT>(...)` (single parentheses) — Issue #1\n- Create new objects in selectors: `useStore((state) => ({ a: state.a }))` — Issue #3\n- Mutate state directly: `set((state) => { state.count++; return state })` — always return a new object (or use immer)\n- Reuse a persist `name` across stores — causes data collisions\n- Use Zustand for server data — use `data-fetching` (TanStack Query) instead\n- Export the store instance directly — always export the `useStore` hook\n\n## Known issues this prevents\n\n### Issue #1: TypeScript double parentheses missing\n\n**Error:** Type inference fails, `StateCreator` types break with middleware.\n\n**Why:** The currying syntax `create\u003CT>()()` is required for middleware to work with TypeScript inference.\n\n```ts\n\u002F\u002F WRONG — single parentheses\nconst useStore = create\u003CMyStore>((set) => ({ \u002F* ... *\u002F }))\n\n\u002F\u002F CORRECT — double parentheses\nconst useStore = create\u003CMyStore>()((set) => ({ \u002F* ... *\u002F }))\n```\n\n**Rule:** Always use `create\u003CT>()()` in TypeScript, even without middleware (future-proof).\n\n### Issue #2: Persist middleware import error\n\n**Error:** `Attempted import error: 'createJSONStorage' is not exported from 'zustand\u002Fmiddleware'`\n\n**Why:** Wrong import path or v4↔v5 version mismatch.\n\n```ts\n\u002F\u002F CORRECT for v5\nimport { create } from \"zustand\"\nimport { persist, createJSONStorage } from \"zustand\u002Fmiddleware\"\n```\n\n### Issue #3: Infinite render loop\n\n**Error:** `Maximum update depth exceeded.` Browser freezes.\n\n**Why:** Creating a new object reference inside the selector. Zustand sees a new reference on every render and re-renders, which creates another new reference, etc. Zustand v5 surfaces this immediately (v4 silently degraded).\n\n```tsx\nimport { useShallow } from \"zustand\u002Fshallow\"\n\n\u002F\u002F WRONG — new object every render\nconst { bears, fishes } = useStore((state) => ({\n  bears: state.bears,\n  fishes: state.fishes,\n}))\n\n\u002F\u002F CORRECT — option 1: select primitives separately\nconst bears = useStore((state) => state.bears)\nconst fishes = useStore((state) => state.fishes)\n\n\u002F\u002F CORRECT — option 2: useShallow for multi-value select\nconst { bears, fishes } = useStore(\n  useShallow((state) => ({ bears: state.bears, fishes: state.fishes }))\n)\n```\n\n### Issue #4: Slices pattern TypeScript complexity\n\n**Error:** `StateCreator` types fail to infer when combining slices.\n\n**Why:** Each slice needs explicit `StateCreator` annotations so the combined store type resolves.\n\n```ts\nimport { create, StateCreator } from \"zustand\"\n\ninterface BearSlice { bears: number; addBear: () => void }\ninterface FishSlice { fishes: number; addFish: () => void }\n\nconst createBearSlice: StateCreator\u003C\n  BearSlice & FishSlice,  \u002F\u002F combined store type\n  [],                     \u002F\u002F middleware mutators (empty if none)\n  [],                     \u002F\u002F chained middleware\n  BearSlice               \u002F\u002F this slice's type\n> = (set) => ({\n  bears: 0,\n  addBear: () => set((state) => ({ bears: state.bears + 1 })),\n})\n\nconst createFishSlice: StateCreator\u003C\n  BearSlice & FishSlice,\n  [],\n  [],\n  FishSlice\n> = (set) => ({\n  fishes: 0,\n  addFish: () => set((state) => ({ fishes: state.fishes + 1 })),\n})\n\nconst useStore = create\u003CBearSlice & FishSlice>()((...a) => ({\n  ...createBearSlice(...a),\n  ...createFishSlice(...a),\n}))\n```\n\n## Middleware\n\n**Persist (UI preferences only):**\n\n```ts\nimport { persist, createJSONStorage } from \"zustand\u002Fmiddleware\"\n\nconst useUiPrefs = create\u003CUiPrefs>()(\n  persist(\n    (set) => ({\n      sidebarCollapsed: false,\n      lastTab: \"overview\",\n      menuOpen: false,\n      setLastTab: (lastTab) => set({ lastTab }),\n    }),\n    {\n      name: \"ui-prefs\",\n      partialize: (state) => ({ sidebarCollapsed: state.sidebarCollapsed, lastTab: state.lastTab }),\n      storage: createJSONStorage(() => localStorage),\n    },\n  ),\n)\n```\n\n`partialize` lets you skip transient fields (open\u002Fclosed flags, drag state) from the saved blob.\n\n**Devtools (Redux DevTools):**\n\n```ts\nimport { devtools } from \"zustand\u002Fmiddleware\"\n\nconst useStore = create\u003CCounterStore>()(\n  devtools(\n    (set) => ({\n      count: 0,\n      increment: () => set((s) => ({ count: s.count + 1 }), undefined, \"increment\"),\n    }),\n    { name: \"CounterStore\" },\n  ),\n)\n```\n\nThe third argument to `set` (`\"increment\"`) becomes the action label in DevTools.\n\n**Combining middlewares (order matters — outer wraps inner):**\n\n```ts\nconst useStore = create\u003CMyStore>()(\n  devtools(\n    persist(\n      (set) => ({ \u002F* state *\u002F }),\n      { name: \"storage\" },\n    ),\n    { name: \"MyStore\" },\n  ),\n)\n```\n\nConventional order: `devtools(persist(immer(stateCreator)))`.\n\n## Common patterns\n\n**Computed \u002F derived values** — compute in the selector, don't store:\n\n```ts\nconst itemCount = useStore((state) => state.items.length)\nconst completedCount = useStore((state) => state.items.filter((i) => i.done).length)\n```\n\n**Async actions:**\n\n```ts\nconst useDataStore = create\u003CDataStore>()((set) => ({\n  data: null,\n  isLoading: false,\n  fetchData: async () => {\n    set({ isLoading: true })\n    const res = await fetch(\"\u002Fapi\u002Fdata\")\n    set({ data: await res.json(), isLoading: false })\n  },\n}))\n```\n\nFor anything that hits `\u002Fapi\u002F...` prefer `data-fetching` (TanStack Query) — Zustand-as-fetcher gives up cache invalidation, retries, request deduplication, and `signal` cancellation.\n\n**Reset to initial state:**\n\n```ts\nconst initialState = { count: 0, name: \"\" }\n\nconst useStore = create\u003CResettableStore>()((set) => ({\n  ...initialState,\n  reset: () => set(initialState),\n}))\n```\n\n**Selector with params (lookup):**\n\n```ts\nconst todo = useStore((state) => state.todos.find((t) => t.id === id))\n```\n\nIf the lookup is expensive and the input is stable, wrap the selector in `useCallback` to keep its reference stable across renders.\n\n## Advanced\n\n**Vanilla store (use outside React):**\n\n```ts\nimport { createStore } from \"zustand\u002Fvanilla\"\n\nconst store = createStore\u003CCounterStore>()((set) => ({\n  count: 0,\n  increment: () => set((s) => ({ count: s.count + 1 })),\n}))\n\nconst unsubscribe = store.subscribe((state) => console.log(state.count))\nstore.getState().increment()\n```\n\nUseful for wiring stores to non-React code (workers, listeners, services).\n\n**Custom middleware:**\n\n```ts\nconst logger: Logger = (f, name) => (set, get, store) => {\n  const loggedSet: typeof set = (...args) => {\n    set(...args)\n    console.log(`[${name}]`, get())\n  }\n  return f(loggedSet, get, store)\n}\n```\n\n**Immer middleware** (mutable-style updates for deeply nested state):\n\n```ts\nimport { immer } from \"zustand\u002Fmiddleware\u002Fimmer\"\n\nconst useKanbanStore = create\u003CKanbanStore>()(\n  immer((set) => ({\n    columns: { todo: { items: [] }, doing: { items: [] }, done: { items: [] } },\n    moveItem: (itemId, fromCol, toCol) => set((state) => {\n      const item = state.columns[fromCol].items.find((i) => i.id === itemId)\n      if (!item) return\n      state.columns[fromCol].items = state.columns[fromCol].items.filter((i) => i.id !== itemId)\n      state.columns[toCol].items.push(item)\n    }),\n  })),\n)\n```\n\n`zustand\u002Fmiddleware\u002Fimmer` needs the `immer` package: `yarn add immer` first. Keep the `()()` pattern: `create\u003CT>()(immer(...))`.\n\n## When to use what\n\n| Need | Use |\n|---|---|\n| Local to one component | `useState` |\n| Frequently changing value (mouse position, scroll) that doesn't need to re-render | `useRef` |\n| Shared across 2+ components (UI flags, selections, modals, kanban state) | **Zustand** |\n| Server data from `\u002Fapi` | **`data-fetching`** (TanStack Query) |\n| Form state | **react-hook-form** (covered by `ui` skill) |\n| Filters \u002F pagination that should live in the URL | `useSearchParams` from react-router |\n| Cross-tab synchronization of persisted state | Zustand `persist` + a storage event listener |\n\n## Common mistakes\n\n- **Destructuring the whole store** — `const { x, y } = useStore()` re-renders on **any** store change (distinct from the new-object-in-selector trap in Issue #3, which infinite-loops). Use `useStore((s) => s.x)` per value, or `useShallow` for a multi-value object.\n\nFor the `()()` currying trap see Issue #1, infinite renders Issue #3, and server-data \u002F mutation \u002F persist-name rules in the Critical rules lists above.\n\n## Official documentation\n\n- Zustand docs: https:\u002F\u002Fzustand.docs.pmnd.rs\u002F\n- TypeScript guide: https:\u002F\u002Fzustand.docs.pmnd.rs\u002Fguides\u002Ftypescript\n- GitHub: https:\u002F\u002Fgithub.com\u002Fpmndrs\u002Fzustand\n","# State Management\n\nZustand for client-side shared state, written against major v5. Already installed in the template (no `yarn add` needed).\n\n**Why Zustand:** zero boilerplate, no providers, ~1 KB, first-class TypeScript, selectors prevent unnecessary re-renders. For this template's app-builder workloads it's the right default; reach for `data-fetching` for server data and `useSearchParams` for URL-synced filters.\n\n## Quick start — TypeScript store\n\nUse `create\u003CT>()()` — double parentheses (see Issue #1 for why).\n\n```ts\nimport { create } from \"zustand\"\n\ninterface BearStore {\n  bears: number\n  increase: (by: number) => void\n}\n\nconst useBearStore = create\u003CBearStore>()((set) => ({\n  bears: 0,\n  increase: (by) => set((state) => ({ bears: state.bears + by })),\n}))\n```\n\n## Use in components\n\nAlways select the specific slice you need — this is what stops unnecessary re-renders:\n\n```tsx\nconst bears = useBearStore((state) => state.bears)        \u002F\u002F re-renders only when bears changes\nconst increase = useBearStore((state) => state.increase)  \u002F\u002F function reference is stable\n```\n\n## Core patterns\n\n**Counter store:**\n\n```ts\ninterface CounterStore { count: number; increment: () => void }\nconst useStore = create\u003CCounterStore>()((set) => ({\n  count: 0,\n  increment: () => set((state) => ({ count: state.count + 1 })),\n}))\n```\n\n**Persistent store — UI preferences only** (theme, collapsed panels, last tab). App data lives in the database through the backend (`web-app`), never in `persist`:\n\n```ts\nimport { persist, createJSONStorage } from \"zustand\u002Fmiddleware\"\n\nconst useStore = create\u003CUserPreferences>()(\n  persist(\n    (set) => ({\n      theme: \"system\",\n      setTheme: (theme) => set({ theme }),\n    }),\n    {\n      name: \"user-preferences\",\n      storage: createJSONStorage(() => localStorage),\n    },\n  ),\n)\n```\n\n## Critical rules\n\n**Always:**\n- Use `create\u003CT>()()` (double parentheses) in TypeScript (Issue #1)\n- Define separate interfaces for state and actions\n- Use selector functions to extract specific state slices\n- Use `set` with updater functions for derived state: `set((state) => ({ count: state.count + 1 }))`\n- Use unique `name` values for each persist-middleware store\n- Use `useShallow` when selecting multiple values into one object\n- Keep actions pure — no side effects beyond state updates\n\n**Never:**\n- Use `create\u003CT>(...)` (single parentheses) — Issue #1\n- Create new objects in selectors: `useStore((state) => ({ a: state.a }))` — Issue #3\n- Mutate state directly: `set((state) => { state.count++; return state })` — always return a new object (or use immer)\n- Reuse a persist `name` across stores — causes data collisions\n- Use Zustand for server data — use `data-fetching` (TanStack Query) instead\n- Export the store instance directly — always export the `useStore` hook\n\n## Known issues this prevents\n\n### Issue #1: TypeScript double parentheses missing\n\n**Error:** Type inference fails, `StateCreator` types break with middleware.\n\n**Why:** The currying syntax `create\u003CT>()()` is required for middleware to work with TypeScript inference.\n\n```ts\n\u002F\u002F WRONG — single parentheses\nconst useStore = create\u003CMyStore>((set) => ({ \u002F* ... *\u002F }))\n\n\u002F\u002F CORRECT — double parentheses\nconst useStore = create\u003CMyStore>()((set) => ({ \u002F* ... *\u002F }))\n```\n\n**Rule:** Always use `create\u003CT>()()` in TypeScript, even without middleware (future-proof).\n\n### Issue #2: Persist middleware import error\n\n**Error:** `Attempted import error: 'createJSONStorage' is not exported from 'zustand\u002Fmiddleware'`\n\n**Why:** Wrong import path or v4↔v5 version mismatch.\n\n```ts\n\u002F\u002F CORRECT for v5\nimport { create } from \"zustand\"\nimport { persist, createJSONStorage } from \"zustand\u002Fmiddleware\"\n```\n\n### Issue #3: Infinite render loop\n\n**Error:** `Maximum update depth exceeded.` Browser freezes.\n\n**Why:** Creating a new object reference inside the selector. Zustand sees a new reference on every render and re-renders, which creates another new reference, etc. Zustand v5 surfaces this immediately (v4 silently degraded).\n\n```tsx\nimport { useShallow } from \"zustand\u002Fshallow\"\n\n\u002F\u002F WRONG — new object every render\nconst { bears, fishes } = useStore((state) => ({\n  bears: state.bears,\n  fishes: state.fishes,\n}))\n\n\u002F\u002F CORRECT — option 1: select primitives separately\nconst bears = useStore((state) => state.bears)\nconst fishes = useStore((state) => state.fishes)\n\n\u002F\u002F CORRECT — option 2: useShallow for multi-value select\nconst { bears, fishes } = useStore(\n  useShallow((state) => ({ bears: state.bears, fishes: state.fishes }))\n)\n```\n\n### Issue #4: Slices pattern TypeScript complexity\n\n**Error:** `StateCreator` types fail to infer when combining slices.\n\n**Why:** Each slice needs explicit `StateCreator` annotations so the combined store type resolves.\n\n```ts\nimport { create, StateCreator } from \"zustand\"\n\ninterface BearSlice { bears: number; addBear: () => void }\ninterface FishSlice { fishes: number; addFish: () => void }\n\nconst createBearSlice: StateCreator\u003C\n  BearSlice & FishSlice,  \u002F\u002F combined store type\n  [],                     \u002F\u002F middleware mutators (empty if none)\n  [],                     \u002F\u002F chained middleware\n  BearSlice               \u002F\u002F this slice's type\n> = (set) => ({\n  bears: 0,\n  addBear: () => set((state) => ({ bears: state.bears + 1 })),\n})\n\nconst createFishSlice: StateCreator\u003C\n  BearSlice & FishSlice,\n  [],\n  [],\n  FishSlice\n> = (set) => ({\n  fishes: 0,\n  addFish: () => set((state) => ({ fishes: state.fishes + 1 })),\n})\n\nconst useStore = create\u003CBearSlice & FishSlice>()((...a) => ({\n  ...createBearSlice(...a),\n  ...createFishSlice(...a),\n}))\n```\n\n## Middleware\n\n**Persist (UI preferences only):**\n\n```ts\nimport { persist, createJSONStorage } from \"zustand\u002Fmiddleware\"\n\nconst useUiPrefs = create\u003CUiPrefs>()(\n  persist(\n    (set) => ({\n      sidebarCollapsed: false,\n      lastTab: \"overview\",\n      menuOpen: false,\n      setLastTab: (lastTab) => set({ lastTab }),\n    }),\n    {\n      name: \"ui-prefs\",\n      partialize: (state) => ({ sidebarCollapsed: state.sidebarCollapsed, lastTab: state.lastTab }),\n      storage: createJSONStorage(() => localStorage),\n    },\n  ),\n)\n```\n\n`partialize` lets you skip transient fields (open\u002Fclosed flags, drag state) from the saved blob.\n\n**Devtools (Redux DevTools):**\n\n```ts\nimport { devtools } from \"zustand\u002Fmiddleware\"\n\nconst useStore = create\u003CCounterStore>()(\n  devtools(\n    (set) => ({\n      count: 0,\n      increment: () => set((s) => ({ count: s.count + 1 }), undefined, \"increment\"),\n    }),\n    { name: \"CounterStore\" },\n  ),\n)\n```\n\nThe third argument to `set` (`\"increment\"`) becomes the action label in DevTools.\n\n**Combining middlewares (order matters — outer wraps inner):**\n\n```ts\nconst useStore = create\u003CMyStore>()(\n  devtools(\n    persist(\n      (set) => ({ \u002F* state *\u002F }),\n      { name: \"storage\" },\n    ),\n    { name: \"MyStore\" },\n  ),\n)\n```\n\nConventional order: `devtools(persist(immer(stateCreator)))`.\n\n## Common patterns\n\n**Computed \u002F derived values** — compute in the selector, don't store:\n\n```ts\nconst itemCount = useStore((state) => state.items.length)\nconst completedCount = useStore((state) => state.items.filter((i) => i.done).length)\n```\n\n**Async actions:**\n\n```ts\nconst useDataStore = create\u003CDataStore>()((set) => ({\n  data: null,\n  isLoading: false,\n  fetchData: async () => {\n    set({ isLoading: true })\n    const res = await fetch(\"\u002Fapi\u002Fdata\")\n    set({ data: await res.json(), isLoading: false })\n  },\n}))\n```\n\nFor anything that hits `\u002Fapi\u002F...` prefer `data-fetching` (TanStack Query) — Zustand-as-fetcher gives up cache invalidation, retries, request deduplication, and `signal` cancellation.\n\n**Reset to initial state:**\n\n```ts\nconst initialState = { count: 0, name: \"\" }\n\nconst useStore = create\u003CResettableStore>()((set) => ({\n  ...initialState,\n  reset: () => set(initialState),\n}))\n```\n\n**Selector with params (lookup):**\n\n```ts\nconst todo = useStore((state) => state.todos.find((t) => t.id === id))\n```\n\nIf the lookup is expensive and the input is stable, wrap the selector in `useCallback` to keep its reference stable across renders.\n\n## Advanced\n\n**Vanilla store (use outside React):**\n\n```ts\nimport { createStore } from \"zustand\u002Fvanilla\"\n\nconst store = createStore\u003CCounterStore>()((set) => ({\n  count: 0,\n  increment: () => set((s) => ({ count: s.count + 1 })),\n}))\n\nconst unsubscribe = store.subscribe((state) => console.log(state.count))\nstore.getState().increment()\n```\n\nUseful for wiring stores to non-React code (workers, listeners, services).\n\n**Custom middleware:**\n\n```ts\nconst logger: Logger = (f, name) => (set, get, store) => {\n  const loggedSet: typeof set = (...args) => {\n    set(...args)\n    console.log(`[${name}]`, get())\n  }\n  return f(loggedSet, get, store)\n}\n```\n\n**Immer middleware** (mutable-style updates for deeply nested state):\n\n```ts\nimport { immer } from \"zustand\u002Fmiddleware\u002Fimmer\"\n\nconst useKanbanStore = create\u003CKanbanStore>()(\n  immer((set) => ({\n    columns: { todo: { items: [] }, doing: { items: [] }, done: { items: [] } },\n    moveItem: (itemId, fromCol, toCol) => set((state) => {\n      const item = state.columns[fromCol].items.find((i) => i.id === itemId)\n      if (!item) return\n      state.columns[fromCol].items = state.columns[fromCol].items.filter((i) => i.id !== itemId)\n      state.columns[toCol].items.push(item)\n    }),\n  })),\n)\n```\n\n`zustand\u002Fmiddleware\u002Fimmer` needs the `immer` package: `yarn add immer` first. Keep the `()()` pattern: `create\u003CT>()(immer(...))`.\n\n## When to use what\n\n| Need | Use |\n|---|---|\n| Local to one component | `useState` |\n| Frequently changing value (mouse position, scroll) that doesn't need to re-render | `useRef` |\n| Shared across 2+ components (UI flags, selections, modals, kanban state) | **Zustand** |\n| Server data from `\u002Fapi` | **`data-fetching`** (TanStack Query) |\n| Form state | **react-hook-form** (covered by `ui` skill) |\n| Filters \u002F pagination that should live in the URL | `useSearchParams` from react-router |\n| Cross-tab synchronization of persisted state | Zustand `persist` + a storage event listener |\n\n## Common mistakes\n\n- **Destructuring the whole store** — `const { x, y } = useStore()` re-renders on **any** store change (distinct from the new-object-in-selector trap in Issue #3, which infinite-loops). Use `useStore((s) => s.x)` per value, or `useShallow` for a multi-value object.\n\nFor the `()()` currying trap see Issue #1, infinite renders Issue #3, and server-data \u002F mutation \u002F persist-name rules in the Critical rules lists above.\n\n## Official documentation\n\n- Zustand docs: https:\u002F\u002Fzustand.docs.pmnd.rs\u002F\n- TypeScript guide: https:\u002F\u002Fzustand.docs.pmnd.rs\u002Fguides\u002Ftypescript\n- GitHub: https:\u002F\u002Fgithub.com\u002Fpmndrs\u002Fzustand\n",{"name":5,"description":7},"main","c54d8e35f50ac35b3b2c7ba8d4fca2205a740cb9","agent-config\u002Fskills\u002Fstate-management",9,"https:\u002F\u002Fgithub.com\u002FSimaDevelopment\u002Fopsiforce","https:\u002F\u002Fgithub.com\u002FSimaDevelopment","2026-11-05 06:13:10",{"source":8,"skillName":5,"commands":52,"prompt":62,"zipAvailable":63},[53,56,59],{"tool":54,"command":55},"npx","npx skills add SimaDevelopment\u002Fopsiforce --skill state-management",{"tool":57,"command":58},"bunx","bunx skills add SimaDevelopment\u002Fopsiforce --skill state-management",{"tool":60,"command":61},"pnpm","pnpm dlx skills add SimaDevelopment\u002Fopsiforce --skill state-management","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSimaDevelopment\u002Fopsiforce\u002Fblob\u002Fmain\u002Fagent-config\u002Fskills\u002Fstate-management\u002FSKILL.md",true,[],[66,91,106,125,133,157],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":39},"01M6QQKHZFGFB6A111RW2A9WC0","figma-use","**MANDATORY prerequisite** — you MUST invoke this skill BEFORE every `use_figma` tool call. NEVER call `use_figma` directly without loading this skill first. Skipping it causes common, hard-to-debug failures. Trigger whenever the user wants to perform a write action or a unique read action that requires JavaScript execution in the Figma file context — e.g. create\u002Fedit\u002Fdelete nodes, set up variables or tokens, build components and variants, modify auto-layout or fills, bind variables to properties, or inspect file structure programmatically.","https:\u002F\u002Fgithub.com\u002FSimaDevelopment\u002Fopsiforce\u002Fblob\u002Fmain\u002Ffrontend\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-use\u002FSKILL.md",[],[73,74,75,23,76,77,78,32,79,80,81,82,83,84,85,86,87,88,89,90],"figma use","figma","use","create","delete","tool","write","edit","context","auto","structure","tokens","bind","Variables","you","inspect","variants","invoke",{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":39},"01M6QQK1AMA90K6DFAVANYQ9X3","figma-use-slides","This skill helps agents use Figma's use_figma MCP tool in the Slides context. Can be used alongside figma-use which has foundational context for using the use_figma tool.","https:\u002F\u002Fgithub.com\u002FSimaDevelopment\u002Fopsiforce\u002Fblob\u002Fmain\u002Ffrontend\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-use-slides\u002FSKILL.md",[],[73,74,98,99,75,100,78,81,101,102,103,104,105],"figma use slides","slides","MCP","false","which","can","for","figma mcp",{"skillNo":107,"name":108,"nameZh":6,"description":109,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":110,"categories":111,"keywords":112,"publishedAt":39},"01M6QQJTR9QYK297WQ1X792D63","figma-use-motion","Motion \u002F animation context for the `use_figma` MCP tool — animating Figma nodes via manual keyframes, animation styles, easing, and timeline duration. Load alongside figma-use whenever a task involves adding, editing, or inspecting animation on a node.","https:\u002F\u002Fgithub.com\u002FSimaDevelopment\u002Fopsiforce\u002Fblob\u002Fmain\u002Ffrontend\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-use-motion\u002FSKILL.md",[],[73,74,113,75,114,100,115,78,116,117,81,118,119,120,101,121,122,123,124,104],"figma use motion","motion","Animation","node","editing","Nodes","task","keyframes","via","styles","manual","load",{"skillNo":126,"name":127,"nameZh":6,"description":128,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":129,"categories":130,"keywords":131,"publishedAt":39},"01M6QQJNZ067ZRXZ6A0QB9M6SB","figma-use-figjam","This skill helps agents use Figma's use_figma MCP tool in the FigJam context. Can be used alongside figma-use which has foundational context for using the use_figma tool.","https:\u002F\u002Fgithub.com\u002FSimaDevelopment\u002Fopsiforce\u002Fblob\u002Fmain\u002Ffrontend\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-use-figjam\u002FSKILL.md",[],[73,74,132,75,100,78,81,101,102,103,104,105],"figma use figjam",{"skillNo":134,"name":135,"nameZh":6,"description":136,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":137,"categories":138,"keywords":139,"publishedAt":39},"01M6QQJ7NEHXPE33VRVHYYM7YE","figma-swiftui","SwiftUI ↔ Figma translation. Use whenever the user mentions Swift, SwiftUI, iOS, iPhone, or iPad — in EITHER direction — translating a Figma design into SwiftUI (design → code), or pushing SwiftUI views \u002F screens \u002F tokens back into a Figma file (code → design). Triggers on phrases like 'implement this Figma design in SwiftUI', 'build this screen in Swift', 'push this SwiftUI view to Figma', 'mirror my Swift code in a Figma file', or whenever a Figma URL appears alongside `.swift` files \u002F an `.xcodeproj`. Routes to a direction-specific reference doc; loads alongside `figma-use` for the code → design path.","https:\u002F\u002Fgithub.com\u002FSimaDevelopment\u002Fopsiforce\u002Fblob\u002Fmain\u002Ffrontend\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-swiftui\u002FSKILL.md",[],[74,140,141,142,143,144,145,146,147,148,149,150,151,152,101,153,154,24,155,156],"figma swiftui","swiftui","design","swift","code","push","doc","files","translation","back","either","iphone","ipad","screen","direction","my","path",{"skillNo":158,"name":159,"nameZh":6,"description":160,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":161,"categories":162,"keywords":163,"publishedAt":39},"01M6QQJ3WZ3M90BZQ5TD305PKN","figma-shaders","**MANDATORY prerequisite** — load this skill before calling `create_shader` or `update_shader`. Use when the user asks to create, author, change, fix, or iterate on a shader effect, shader fill, custom effect, custom fill, or procedural shader in Figma.","https:\u002F\u002Fgithub.com\u002FSimaDevelopment\u002Fopsiforce\u002Fblob\u002Fmain\u002Ffrontend\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-shaders\u002FSKILL.md",[],[164,74,165,166,76,167,168,169,170,75,171,172,101,173,124,174,175,176,177],"shaders","figma shaders","change","update","effect","user","fix","shader","calling","procedural","fill","iterate","custom","author"]