zustand-5

Implement Zustand 5 store patterns for React state management.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamlines React state management by offering a practical set of Zustand patterns, including basic stores, persistence, selectors, async actions, slices, Immer, DevTools, and external usage.

Core Features & Use Cases

  • Basic Store: simple, typed Zustand store for component state.
  • Persist Middleware: persists state to localStorage to survive refreshes.
  • Selectors (Zustand 5): select precise fields to minimize re-renders and use shallow for multiple fields.
  • Async Actions: fetch and manage asynchronous data with loading and error handling.
  • Slices Pattern: compose multiple slices into a single, modular store.
  • Immer Middleware: enable immutable mutations via Immer.
  • DevTools: integrate with Zustand devtools for debugging and inspection.
  • Outside React: read and subscribe to stores outside components.

Quick Start

Create a Zustand store using zustand-5 patterns and integrate it into a React component to manage simple state.

Frequently Asked Questions about zustand-5

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

FAQPage Schema
How do I manage React state with Zustand 5 using slices and selectors?

To manage React state with Zustand 5, you compose modular slices into a single store and use selectors to extract precise fields. Using shallow equality checks on selectors minimizes unnecessary component re-renders.

How to persist Zustand store state to localStorage in a React app?

To persist Zustand store state, you apply the persist middleware during store creation. This middleware automatically saves your React state to localStorage, allowing the store to survive page refreshes and rehydration.

Does Zustand 5 support async actions for data fetching in React?

Yes, Zustand 5 supports async actions for data fetching in React. You can define asynchronous functions directly within your store to handle loading states, error management, and API data population seamlessly.

Can I read and subscribe to a Zustand store outside of React components?

You can read and subscribe to a Zustand store outside of React components. The store acts as a standalone hook, allowing external modules to access state and subscribe to updates independently of the React render cycle.

What is the best way to handle immutable state mutations in Zustand?

The best way to handle immutable state mutations in Zustand is by integrating the Immer middleware. This middleware enables you to write standard mutable JavaScript syntax while automatically generating immutable state updates.

Do I need TypeScript to use modular store architecture with Zustand 5?

TypeScript is not strictly required, but it is recommended for Zustand 5 modular store architectures. TypeScript types provide robust autocompletion and type safety when composing slices and defining store interfaces.