0.0.1 • Published 1 year ago
@jasonpang/zen-store v0.0.1
zen-store
An extremely simple react store works with React.useSyncExternalStore
Install
npm i zen-store -S
Usage
import React, { useSyncExternalStore } from "react";
import ZenStore from 'zen-store';
const Store = new ZenStore(0);
function Button() {
const handleClick = () => {
Store.update(Store.getSnapshot() + 1)
}
return <button role="button" onClick={handleClick}>add</button>
}
function Counter() {
const count = useSyncExternalStore(Store.subscribe.bind(Store), Store.getSnapshot.bind(Store));
return <div role="counter">
<i role="count">{count}</i>
<Button />
</div>
}
0.0.1
1 year ago