Introduction to Valtio

Learn about Valtio and when to use it.

Getting started

In this course, we learn about a lightweight state management library, Valtio. Valtio is based on proxies and lets you provide a small API surface. By learning its basics, we learn how to create a global state instantly in React.

What is Valtio?

Valtio is a small library for React global state. There are many global state libraries in the React ecosystem. Valtio tries to toss a new option with minimal possible APIs, proxy and useSnapshot.

It utilizes the Proxy API in JavaScript. There are several libraries for React which utilize proxies but what distinguishes Valtio from them is its React Hooks API.

The Valtio API is designed to be intuitive and straightforward. It also tries to follow the upcoming React features (something called Concurrent Mode).

When to use Valtio?

Valtio provides basic functionality and can be used in various cases. It works for a small global state that would be shared between components. It works for a larger state to hold the entire application state.

It doesn’t come with additional features, which means that developers have to create them. In most cases, it is easy and straightforward to add such features.

Important Note

Valtio is based on:

  • state mutation style, which may not fit with project coding style.
  • proxies, which can be troublesome in some minor cases.