DEV Community

Alex Spinov
Alex Spinov

Posted on

Valtio Has a Free API That Most Developers Dont Know About

Valtio makes proxy-based state management simple. Mutate state directly — React auto re-renders.

Usage

import { proxy, useSnapshot } from "valtio";

const state = proxy({ count: 0, todos: [] });
state.count++; // mutate directly
state.todos.push("item");

function Counter() {
  const snap = useSnapshot(state);
  return <button onClick={() => state.count++}>{snap.count}</button>;
}
Enter fullscreen mode Exit fullscreen mode

Derived

import { derive } from "valtio/utils";
const derived = derive({ doubled: (get) => get(state).count * 2 });
Enter fullscreen mode Exit fullscreen mode

Key Features

  • Mutable API
  • Proxy-based reactivity
  • Derived state
  • Tiny bundle (3KB)

Need to scrape or monitor web data at scale? Check out my web scraping actors on Apify or email spinov001@gmail.com for custom solutions.

Top comments (0)