valtio
БесплатноБез исполняемых скриптовНе проверенValtio is a proxy-based state library for React: wrap an object in proxy(), mutate it like plain JavaScript, and components that read it through useSnapshot…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Valtio
Overview
Valtio makes React state management feel like plain JavaScript — mutate objects directly and React re-renders automatically. No reducers, no actions, no selectors. Wrap an object in proxy(), mutate it anywhere, and components that read the changed properties re-render. Based on JavaScript Proxy, it tracks which properties each component uses and only re-renders when those specific properties change.
This skill targets Valtio 2 (current release 2.3.x). Compared with v1: promises stored in a proxy are no longer resolved for you, proxy(obj) wraps the object you pass instead of copying it, and derive is no longer part of valtio/utils.
When to Use
- Want the simplest possible state management
- Tired of Redux boilerplate or Zustand's
set()function - Sharing state between components without prop drilling
- State that's accessed/modified outside React (event handlers, WebSocket callbacks)
- Team prefers mutable patterns over immutable
Instructions
Setup
npm install valtio
Basic Store
// store/app.ts — Define state as a plain object
import { proxy } from "valtio";
export const appState = proxy({
user: null as { name: string; email: string } | null,
theme: "light" as "light" | "dark",
notifications: [] as Array<{ id: string; text: string; read: boolean }>,
sidebar: { open: true, width: 280 },
// Computed value: an object getter that reads sibling properties through `this`
get unreadCount() {
return this.notifications.filter((n) => !n.read).length;
},
});
// Mutate directly — React components auto-update
export function login(user: { name: string; email: string }) {
appState.user = user;
}
export function toggleTheme() {
appState.theme = appState.theme === "light" ? "dark" : "light";
}
export function addNotification(text: string) {
appState.notifications.push({ id: crypto.randomUUID(), text, read: false });
}
export function markAllRead() {
appState.notifications.forEach((n) => { n.read = true; });
}
export function toggleSidebar() {
appState.sidebar.open = !appState.sidebar.open;
}
Use in Components
Read from the snapshot while rendering; write to the proxy (and read from it inside callbacks).
// components/Header.tsx — Read state with useSnapshot
import { useSnapshot } from "valtio";
import { appState, toggleTheme, toggleSidebar, markAllRead } from "../store/app";
export function Header() {
// useSnapshot creates a read-only snapshot
// Component ONLY re-renders when `user`, `theme` or `unreadCount` changes
// Changes to `sidebar` don't trigger a re-render here
const snap = useSnapshot(appState);
return (
<header>
<button onClick={toggleSidebar}>Menu</button>
<span>{snap.user?.name ?? "Guest"}</span>
<button onClick={markAllRead}>Inbox ({snap.unreadCount})</button>
<button onClick={toggleTheme}>{snap.theme === "light" ? "Dark" : "Light"} mode</button>
</header>
);
}
export function SearchBox({ form }: { form: { query: string } }) {
// `form` is a proxy; sync: true turns off update batching, which controlled inputs need
const snap = useSnapshot(form, { sync: true });
return <input value={snap.query} onChange={(e) => { form.query = e.target.value; }} />;
}
Computed Values
A getter can only read properties of its own object (siblings via this). On the proxy it is recalculated on every access; in a snapshot the value is captured once. In v1 this job was often done with derive from valtio/utils; that export was removed in v2, and both its successor package derive-valtio and the built-in watch util are now deprecated in favour of valtio-reactive (computed, effect, batch). For a value that depends on another proxy, keep it in sync with subscribe:
// store/greeting.ts — derive from a different proxy
import { proxy, subscribe } from "valtio";
import { appState } from "./app";
export const greeting = proxy({ text: "Hello, Guest" });
subscribe(appState, () => {
greeting.text = `Hello, ${appState.user?.name ?? "Guest"}`;
});
Subscribe Outside React
// store/effects.ts — Listen to state changes outside components
import { subscribe, snapshot } from "valtio";
import { subscribeKey } from "valtio/utils";
import { appState } from "./app";
// Any change in the tree; mutations in the same tick are batched into one call
const unsubscribe = subscribe(appState, () => {
console.log("State changed:", JSON.stringify(snapshot(appState)));
});
// A nested object can be subscribed to on its own
subscribe(appState.sidebar, () => {
localStorage.setItem("sidebar-open", String(appState.sidebar.open));
});
// A primitive property needs subscribeKey — subscribe() only accepts proxy objects
subscribeKey(appState, "theme", (theme) => {
document.documentElement.dataset.theme = theme;
});
// Mutate from any callback, for example a WebSocket handler
const socket = new WebSocket("wss://a
Установить valtio в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл valtio?
Valtio is a proxy-based state library for React: wrap an object in proxy(), mutate it like plain JavaScript, and components that read it through useSnapshot re-render only for the properties they used. Use when someone asks for "simple React state management", "Valtio", "proxy state", "mutable state in React", "alternative to Zustand/Redux", or "state management without boilerplate". Covers Valtio 2: proxy state, snapshots, subscriptions, computed getters, async values with React's use hook, proxyMap/proxySet, and devtools.
Как установить скилл valtio?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл valtio запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic