zustand-stores

Create SSR-safe Zustand authentication stores with actions and selectors.

27|2|Updated Oct 10, 2023
One-click install
npx skills add https://github.com/aexol-studio/axolotl --skill zustand-stores
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zustand-stores
Source: https://github.com/aexol-studio/axolotl/tree/main/examples/new/.opencode/skills/zustand-stores
Command: npx skills add https://github.com/aexol-studio/axolotl --skill zustand-stores

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Zust and stores provide a lightweight, type-safe pattern for sharing UI and authentication state across React components with SSR-safe initialization, ensuring server-rendered HTML and client navigation stay in sync without hydration headaches.

Core Features & Use Cases

  • SSR-safe initialization from server-provided data (e.g., window.INITIAL_AUTH) to hydrate initial state
  • Centralized access via useAuthStore and useAuthStore.getState() for helpers
  • Clear separation of concerns with actions and selectors in Zustand stores
  • Lightweight, easily testable pattern suitable for auth flows and UI state

Quick Start

Initialize the auth store at startup and read isAuthenticated with useAuthStore((s) => s.isAuthenticated).

Frequently Asked Questions about zustand-stores

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

FAQPage Schema
How do I manage authentication state in React with Zustand during SSR?

To manage authentication state with Zustand during SSR, initialize the auth store using server-provided data like window.__INITIAL_AUTH__. This hydrates the initial state safely, keeping server-rendered HTML and client navigation in sync without hydration mismatches.

What is SSR-safe state initialization in React?

SSR-safe state initialization is the process of seeding a client-side store with server-rendered data before hydration. It prevents hydration mismatches by ensuring the server-generated HTML and the client's initial state match perfectly upon loading.

How do I access Zustand store state outside of React components?

You can access Zustand store state outside React components by calling the getState() method directly on the store hook, such as useAuthStore.getState(). This provides centralized access to helpers and current state values.

Can I use Zustand for authentication flows in a TypeScript app?

Yes, you can use Zustand for auth flows in a TypeScript app because it provides a lightweight, type-safe pattern. It allows clear separation of concerns with actions and selectors, making authentication logic easily testable.

Why does my Zustand store cause hydration errors on the client?

Hydration errors occur when the client's initial state differs from the server-rendered HTML. To fix this, ensure SSR-safe initialization by populating your Zustand store with server-provided session data before client hydration begins.