zustand-5

Implement Zustand stores with persistence, selectors, async actions, and middleware.

Updated Nov 19, 2024
One-click install
npx skills add https://github.com/Strocs/.dotfiles --skill zustand-5-strocs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zustand-5
Source: https://github.com/Strocs/.dotfiles/tree/main/.config/opencode/skills/zustand-5
Command: npx skills add https://github.com/Strocs/.dotfiles --skill zustand-5-strocs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Zustand patterns help manage React state more predictably by organizing stores, persistence, and actions in a scalable way.

Core Features & Use Cases

  • Basic Store: A simple state container with read/write state and actions.
  • Persist Middleware: Persist state across page reloads.
  • Selectors: Efficiently read specific fields to avoid unnecessary re-renders.
  • Async Actions: Handle data fetching and side effects in stores.
  • Slices Pattern: Compose multiple slices into a single store.
  • Immer Middleware: Mutate state immutably with Immer.
  • DevTools: Integrate with devtools for debugging.

Quick Start

Use zustand-5 to implement a basic store, then progressively add persistence, selectors, async actions, slices, and middleware in your React project.

Frequently Asked Questions about zustand-5

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

FAQPage Schema
How do I persist Zustand state across page reloads in React?

Persist Zustand state across page reloads by applying the persist middleware to your store, which automatically saves and rehydrates state data. This middleware ensures your React state remains intact during browser refreshes.

What is the slices pattern for composing multiple Zustand stores?

The slices pattern composes multiple independent state slices into a single Zustand store for modular React state management. Each slice defines its own state and actions, which are then combined to create a unified store.

How do I use selectors to prevent unnecessary re-renders in Zustand?

Use selectors in Zustand to efficiently read specific state fields and prevent unnecessary React re-renders. By selecting only the required data fields, components skip re-rendering when unrelated state properties change.

Can I integrate Immer middleware with Zustand for immutable state updates?

You can integrate Immer middleware with Zustand to mutate state immutably using standard JavaScript syntax. The middleware translates your direct mutations into immutable updates behind the scenes for your React store.

How do I handle async actions and data fetching in a Zustand store?

Handle async actions and data fetching in a Zustand store by defining asynchronous functions within your store configuration. These actions manage side effects and update the React state once the asynchronous data retrieval resolves.

Does Zustand 5 support devtools for debugging React state?

Zustand 5 supports devtools integration to inspect and debug your React state management logic. Connecting the devtools middleware allows you to track state changes and action history during application development.