add-scoped-store

Create per-entity scoped Zustand stores with getOrCreate and useScoped APIs.

1|Updated Mar 27, 2026
One-click install
npx skills add https://github.com/kibertoad/tanstack-react-modules --skill add-scoped-store
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: add-scoped-store
Source: https://github.com/kibertoad/tanstack-react-modules/tree/main/skills/add-scoped-store
Command: npx skills add https://github.com/kibertoad/tanstack-react-modules --skill add-scoped-store

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Per-entity scoped Zustand stores solve the problem of isolating state across multiple independent entities (e.g., tabs, conversations, workspaces) without creating global singletons or leaking state between contexts.

Core Features & Use Cases

  • Factory to create per-entity scoped stores with an initializer.
  • getOrCreate(scopeId) to obtain a per-scope store instance.
  • useScoped(scopeId) and useScoped(scopeId, selector) for React components.
  • Cleanup behavior to remove unused scopes and prevent memory leaks.

Quick Start

Create a per-entity scoped store and use getOrCreate and useScoped to manage state for a specific ID.

Frequently Asked Questions about add-scoped-store

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

FAQPage Schema
How do I isolate state per entity in React without global singletons?

Per-entity scoped Zustand stores isolate state across independent entities like tabs or workspaces by creating isolated store instances per scope ID, preventing state leakage between contexts without relying on global singletons.

How do I manage isolated Zustand stores for multiple items or workspaces?

You can manage isolated Zustand stores using the createScopedStore API to initialize per-scope stores, then call getOrCreate with a scope ID to obtain or create the specific store instance for that entity.

Can I use scoped Zustand stores outside of React components?

Yes, scoped Zustand stores work outside React components by using the getOrCreate function with a scope ID to access isolated state instances, while useScoped is used specifically within React component trees.

How do I prevent memory leaks when using per-entity state management in React?

To prevent memory leaks with per-entity state management, use the built-in cleanup behavior to remove unused scopes and their associated store instances when entities are no longer active or needed.

What is the best way to handle per-tab state in a React and TypeScript application?

The best way to handle per-tab state is defining per-entity scoped Zustand stores with TypeScript types, using useScoped within components and getOrCreate in non-React code to manage isolated state per tab ID.

Do I need TypeScript to implement scoped stores for entity-specific state?

Yes, TypeScript types are required to implement scoped stores, as the createScopedStore API relies on TypeScript to initialize per-scope stores and dynamically patch actions across entities and lifecycles.