zustand-mutative-pattern

Enforce context-scoped Zustand stores with mutative updates and namespaced actions.

7|2|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/wenerme/ai --skill zustand-mutative-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zustand-mutative-pattern
Source: https://github.com/wenerme/ai/tree/main/skills/zustand-mutative-pattern
Command: npx skills add https://github.com/wenerme/ai --skill zustand-mutative-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents brittle and unsafe Zustand state management by enforcing a specific architecture for context-scoped stores, namespaced actions, and deep mutative updates.

Core Features & Use Cases

  • Actions namespace enforcement: All state modifications must be grouped under an actions object rather than being scattered across root state.
  • Context isolation for SSR safety: Stores must be provided via React Context (no global singleton Zustand stores).
  • Deep mutative updates: Uses mutative from zustand-mutative to update nested state without unsafe spreads.
  • Performance-friendly selectors: Requires useShallow when selecting multiple properties together.
  • Side-effect separation: Store emits events; UI/network/toasts/dialogs belong in Sidecar components, not in the store.

Quick Start

Use the zustand-mutative-pattern skill to implement a context-scoped Zustand store that updates nested UI state using mutative and exposes mutations only through an actions namespace.

Frequently Asked Questions about zustand-mutative-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a context-scoped Zustand store for SSR safety?

To create a context-scoped Zustand store for SSR safety, provide the store via React Context instead of using a global singleton. This pattern isolates UI state across server-side rendering requests and nested UI modules, preventing cross-request state leakage.

What is the best way to structure actions in a Zustand store?

The best way to structure actions in a Zustand store is to group all state modifications under a dedicated `actions` namespace object. This prevents mutations from scattering across root state and standardizes action-based state transitions, keeping logic predictable.

How do I perform deep mutative updates in Zustand without unsafe spreads?

You perform deep mutative updates in Zustand by using the `mutative` function from `zustand-mutative`. This allows you to directly modify nested state structures safely without relying on brittle object spread syntax or manual immutable updates.

Why should I use useShallow when selecting multiple Zustand state properties?

You should use `useShallow` when selecting multiple Zustand state properties together to prevent unnecessary re-renders. It ensures React components only re-render when the selected output actually changes, optimizing rendering performance.

How do I handle side-effects like toasts and network calls in a Zustand store?

To handle side-effects like toasts and network calls, emit events from your Zustand store and isolate these UI and network interactions in Sidecar components. This approach prevents impure logic from polluting the bounded store.