talira

Proxy-based state for React and vanilla JavaScript

open sourceMITfree

Valtio is a state management library that turns a plain object into a proxy you can mutate from anywhere, the way you'd change a normal JavaScript object. In React, useSnapshot gives a component a read-only snapshot and re-renders it only when the parts of the state it reads change. It also works without React through valtio/vanilla, and comes from Poimandres, the makers of Jotai.

Problems it solves

  • share mutable state between React components without reducers
  • re-render only the components that use the part of state that changed
  • manage app state the same way inside and outside React

Features

  • mutate state directly with ordinary assignments
  • useSnapshot re-renders a component only when the state it reads changes
  • subscribe to changes from outside React
  • Suspense support for promises in state
  • Redux DevTools integration through valtio/utils
  • proxySet and proxyMap helpers and computed properties

Limitations

  • Valtio v2 needs React 18 or later.1

Alternatives

The same job

These do what Valtio does.

  1. Zustand Bear necessities for React state
  2. MobX Simple, scalable state management
  3. Jotai Atomic state management for React
  4. Immer Work with immutable state by writing ordinary mutating code
  5. Redux A JS library for predictable global state management

Compare Valtio with the top 3