← 返回 Skills 市场
anderskev

Zustand State

作者 Kevin Anderson · GitHub ↗ · v1.1.0 · MIT-0
cross-platform ✓ 安全检测通过
158
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install zustand-state
功能描述
Zustand state management for React and vanilla JavaScript. Use when creating stores, using selectors, persisting state to localStorage, integrating devtools,...
使用说明 (SKILL.md)

Zustand State Management

Minimal state management - no providers, minimal boilerplate.

Quick Reference

import { create } from 'zustand'

interface BearState {
  bears: number
  increase: (by: number) => void
}

const useBearStore = create\x3CBearState>()((set) => ({
  bears: 0,
  increase: (by) => set((state) => ({ bears: state.bears + by })),
}))

// In component - select only what you need
const bears = useBearStore((state) => state.bears)
const increase = useBearStore((state) => state.increase)

State Updates

// Flat updates (auto-merged at one level)
set({ bears: 5 })
set((state) => ({ bears: state.bears + 1 }))

// Nested objects (manual spread required)
set((state) => ({
  nested: { ...state.nested, count: state.nested.count + 1 }
}))

// Replace entire state (no merge)
set({ bears: 0 }, true)

Selectors & Performance

// Good - subscribes only to bears
const bears = useBearStore((state) => state.bears)

// Bad - rerenders on any change
const state = useBearStore()

// Multiple values with useShallow (prevents rerenders with shallow comparison)
import { useShallow } from 'zustand/react/shallow'

const { bears, fish } = useBearStore(
  useShallow((state) => ({ bears: state.bears, fish: state.fish }))
)

// Array destructuring also works
const [bears, fish] = useBearStore(
  useShallow((state) => [state.bears, state.fish])
)

Access Outside Components

// Get current state (non-reactive)
const state = useBearStore.getState()

// Update state
useBearStore.setState({ bears: 5 })

// Subscribe to changes
const unsub = useBearStore.subscribe((state) => console.log(state))
unsub() // unsubscribe

Vanilla Store (No React)

import { createStore } from 'zustand/vanilla'

const store = createStore((set) => ({
  bears: 0,
  increase: (by) => set((state) => ({ bears: state.bears + by })),
}))

store.getState().bears
store.setState({ bears: 10 })
store.subscribe((state) => console.log(state))

Additional Documentation

Key Patterns

Pattern When to Use
Single selector One piece of state needed
useShallow Multiple values, avoid rerenders
getState() Outside React, event handlers
subscribe() External systems, logging
Vanilla store Non-React environments
安全使用建议
This skill is a set of documentation and example code for Zustand — it appears coherent with its description and does not request secrets or install anything. Before installing, consider: 1) the source/homepage is missing, so if you prefer official or tracked sources use the upstream Zustand docs or the package repository; 2) code snippets illustrating persistence (localStorage/asyncStorage) will store data in the browser if you copy them into an app — review what you persist to avoid saving sensitive data; 3) this skill does not execute code by itself (it only provides examples), but an agent might generate or suggest code based on these examples, so review generated code before running it. If you need provenance guarantees, prefer a skill that links to an official repo or maintainer.
功能分析
Type: OpenClaw Skill Name: zustand-state Version: 1.1.0 The skill bundle is a comprehensive documentation and reference guide for the Zustand state management library. It contains standard code snippets for React and vanilla JavaScript, covering middleware (persist, devtools, immer), design patterns (slices, testing), and TypeScript integration across files like SKILL.md, MIDDLEWARE.md, and PATTERNS.md. No malicious logic, data exfiltration, or prompt injection attempts were identified.
能力评估
Purpose & Capability
Name and description match the provided materials: the files are documentation and code examples for using Zustand in React and vanilla JS. There are no environment variables, binaries, or install steps required that would be unrelated to a docs/tutorial skill. Note: the skill's source/homepage are missing which reduces traceability but does not conflict with the skill's stated purpose.
Instruction Scope
SKILL.md and reference files contain code snippets and guidance for creating stores, middleware, persistence (localStorage), devtools, testing, and TypeScript patterns. The instructions do not direct the agent to read unrelated system files or exfiltrate data, nor do they instruct network calls to third-party endpoints (the example fetch('/api/data') is illustrative of typical usage). No vague 'gather whatever context you need' phrasing grants broad discretion.
Install Mechanism
No install spec is present; this is instruction-only documentation. Nothing will be downloaded or written to disk by an installer, so install-risk is minimal.
Credentials
The skill declares no required environment variables, credentials, or config paths. The examples mention localStorage and an illustrative asyncStorage abstraction (expected for persistence examples) but do not require access to secrets or unrelated services.
Persistence & Privilege
always is false and the skill does not request persistent system presence or modify other skills' configs. It is an on-demand, user-invocable documentation skill with normal autonomy settings.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install zustand-state
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /zustand-state 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.1.0
- Expanded documentation with usage examples, reference patterns, and performance tips. - Added sections for state updates, selectors, shallow comparison, and access outside React. - Included quick reference code for both React and vanilla JavaScript usage. - Linked to additional documentation for middleware, patterns, and TypeScript. - Updated description to summarize triggers and use cases.
元数据
Slug zustand-state
版本 1.1.0
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 1
常见问题

Zustand State 是什么?

Zustand state management for React and vanilla JavaScript. Use when creating stores, using selectors, persisting state to localStorage, integrating devtools,... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 158 次。

如何安装 Zustand State?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install zustand-state」即可一键安装,无需额外配置。

Zustand State 是免费的吗?

是的,Zustand State 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Zustand State 支持哪些平台?

Zustand State 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Zustand State?

由 Kevin Anderson(@anderskev)开发并维护,当前版本 v1.1.0。

💬 留言讨论