valtio

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Valtio makes proxy-state simple for React and vanilla JavaScript. It provides a minimal, flexible, and unopinionated API that turns objects into self-aware proxies, enabling fine-grained subscription and reactivity. Valtio shines at render optimization in React and is compatible with Suspense and React 18+.
The skill is based on Valtio v2.3.0, generated at 2026-01-29.
Valtio 让 React 和原生 JavaScript 中的代理状态管理变得简单。它提供了一个轻量、灵活且无偏见的 API,可将对象转换为具备自我感知能力的代理,实现细粒度的订阅和响应式特性。Valtio 在 React 渲染优化方面表现出色,并且兼容 Suspense 和 React 18+。
本技能基于 Valtio v2.3.0,生成于2026年1月29日。

Core References

核心参考

TopicDescriptionReference
ProxyCreate reactive state objects that track changescore-proxy
useSnapshotReact hook for render-optimized state accesscore-use-snapshot
SnapshotCreate immutable snapshots for comparison and Suspensecore-snapshot
SubscribeSubscribe to state changes from anywherecore-subscribe
主题描述参考链接
Proxy创建可跟踪变更的响应式状态对象core-proxy
useSnapshot用于优化渲染的React状态访问Hookcore-use-snapshot
Snapshot创建用于比较和Suspense的不可变快照core-snapshot
Subscribe从任意位置订阅状态变更core-subscribe

Utils

工具函数

TopicDescriptionReference
proxyMapObservable Map-like proxy for Map data structuresutils-proxy-map
proxySetObservable Set-like proxy for Set data structuresutils-proxy-set
subscribeKeySubscribe to changes of a specific propertyutils-subscribe-key
DevToolsRedux DevTools Extension integrationutils-devtools
RefCreate unproxied references for special objectsutils-ref
主题描述参考链接
proxyMap适用于Map数据结构的可观察类Map代理utils-proxy-map
proxySet适用于Set数据结构的可观察类Set代理utils-proxy-set
subscribeKey订阅特定属性的变更utils-subscribe-key
DevToolsRedux DevTools扩展集成utils-devtools
Ref为特殊对象创建非代理引用utils-ref

Guides

指南

TopicDescriptionReference
Component StateIsolate component state using useRefguides-component-state
Computed PropertiesCreate computed properties with getters and settersguides-computed-properties
AsyncWork with promises and React Suspenseguides-async
主题描述参考链接
Component State使用useRef隔离组件状态guides-component-state
Computed Properties使用getter和setter创建计算属性guides-computed-properties
Async处理Promise和React Suspenseguides-async

Best Practices

最佳实践

TopicDescriptionReference
ActionsOrganize actions for mutating statebest-practices-actions
PersistencePersist state to localStorage or other storagebest-practices-persistence
State CompositionSplit and compose states for organizationbest-practices-state-composition
主题描述参考链接
Actions组织用于修改状态的动作best-practices-actions
Persistence将状态持久化到localStorage或其他存储best-practices-persistence
State Composition拆分并组合状态以实现模块化管理best-practices-state-composition