schummar-state
v0.4.8
Published
(React) state library
Downloads
110
Readme
Lighweight React hooks based state library. Heavily inspired by pullstate
Getting started
Install
npm install schummar-state
Create a store
import { Store } from 'schummar-state';
export const store = new Store({
counter: 0,
});
You can easily use multiple stores in parallel.
Use store in a component
import store from './store.ts';
export function App() {
const counter = store.useState((state) => state.counter);
return (
<div>
<div>Counter: {counter}</div>
</div>
);
}
Update a store
import store from './store.ts';
export function App() {
const counter = store.useState((state) => state.counter);
const increment = () =>
store.update((state) => {
state.counter++;
});
return (
<div>
<div>Counter: {counter}</div>
<button onClick={increment}>Increment</button>
</div>
);
}