npm install @illostack/react-storenpm install @illostack/storeYou can create a store using createStore, which accepts an object defining the initial state.
import { createStore } from "@illostack/store";
const store = createStore({
count: 0
});useStore Hook
import { useStore } from "@illostack/react-store";
const Counter = () => {
const count = useStore(store, state => state.count);
return <div>{count}</div>;
};useStoreEffect Hook
import { useStoreEffect } from "@illostack/react-store";
const Counter = () => {
useStoreEffect(store, state => state.count, (state, prevState) => {
console.log("Count changed", state.count);
});
// No re-renders
...
};You can update the state of the store using the update method.
store.update(state => ({ count: state.count + 1 }));