zustand-valtio
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

zustand-valtio

CI npm size discord

A sweet combination of Zustand and Valtio

Install

npm install zustand zustand-valtio valtio

Usage

import { createWithProxy } from 'zustand-valtio';

const [useCounterState, counterState] = createWithProxy({ count: 0 });

const Counter = () => {
  const count = useCounterState((state) => state.count);
  const inc = () => ++counterState.count;
  return (
    <div>
      {count} <button onClick={inc}>+1</button>
    </div>
  );
};

But, why?

Zustand has immer middleware to update state mutably. Valtio has the same capability. Isn't the combination is sweet?

Examples

The examples folder contains working examples. You can run one of them with

PORT=8080 yarn run examples:01_counter

and open http://localhost:8080 in your web browser.

You can also try them in codesandbox.io: 01 02

Tweets

Readme

Keywords

Package Sidebar

Install

npm i zustand-valtio

Weekly Downloads

47

Version

0.2.0

License

MIT

Unpacked Size

8.12 kB

Total Files

9

Last publish

Collaborators

  • daishi