Skills2026年5月15日·1 分钟阅读

Nanostores — Tiny State Manager for Any Framework

Framework-agnostic state management in under 1kB with first-class support for React, Vue, Svelte, and vanilla JS.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Nanostores Overview
直接安装命令
npx -y tokrepo@latest install c794dbad-4ff5-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Nanostores is a minimalist state management library designed to work across any JavaScript framework. At under 1kB, it provides atoms for simple values, maps for key-value objects, and computed stores for derived state. Official integrations exist for React, Vue, Svelte, Solid, Lit, and Angular, making it an ideal choice for multi-framework projects or micro-frontend architectures.

What Nanostores Does

  • Manages shared state with atom, map, and deepMap store primitives
  • Derives computed values that update automatically when dependencies change
  • Provides framework bindings that subscribe components to store changes
  • Supports lazy initialization with lifecycle hooks for mount and unmount
  • Handles async data loading through the @nanostores/query addon

Architecture Overview

Nanostores uses a publish-subscribe model where each store is an observable container. When a store value changes, all subscribers are notified synchronously. Computed stores track their dependencies automatically and recalculate only when inputs change. Framework integrations use the subscribe API to bridge stores with each framework's reactivity system.

Self-Hosting & Configuration

  • Install the core package plus a framework-specific binding package
  • Create store files that export atoms and computed stores
  • Import and use stores directly in components via framework hooks
  • No provider wrappers or context setup required
  • TypeScript types are inferred automatically from store definitions

Key Features

  • Under 1kB core with zero dependencies
  • Works with React, Vue, Svelte, Solid, Lit, Angular, and vanilla JS
  • Atom, map, and deepMap primitives for different data shapes
  • Lazy store initialization that activates only when subscribed
  • Built-in router store for lightweight client-side routing

Comparison with Similar Tools

  • Zustand — React-specific with larger API; Nanostores is framework-agnostic
  • Jotai — React-only atomic state; similar atom concept but tighter React coupling
  • Pinia — Vue-specific store; richer devtools but locked to Vue ecosystem
  • Valtio — proxy-based state with React focus; mutable API style

FAQ

Q: Why choose Nanostores over Zustand or Jotai? A: Nanostores works across multiple frameworks, making it the go-to choice for shared state in micro-frontend or multi-framework projects.

Q: Can I use Nanostores for server-side rendering? A: Yes. Stores are plain JavaScript objects that work in any environment. Framework bindings handle SSR hydration automatically.

Q: How does lazy initialization work? A: Stores with onMount callbacks only activate when a component subscribes. When all subscribers disconnect, the cleanup function runs.

Q: Is Nanostores suitable for large applications? A: Yes. The modular store-per-feature pattern scales well, and computed stores handle derived state efficiently.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产