0.2.2 • Published 3 years ago
petx v0.2.2
petx
An easy-to-use state management in React
try it in stackblitz
quick start
npm install petx
import { createStore } from "petx";
const CounterStore = createStore({ count: 0 });
const Counter = () => {
const { count, setStoreState } = CounterStore.useStore();
return (
<button type="button" onClick={() => setStoreState({ count: count + 1 })}>
count from CounterStore is: {count}
</button>
);
};
const Double = () => {
const { count } = CounterStore.useStore();
return <button type="button">{count * 2}</button>;
};
const Wrap = () => {
return (
<>
<p>Hello petx + React!</p>
<Counter />
<Double />
</>
);
};
const App = () => {
return (
<CounterStore.Provider>
<Wrap />
</CounterStore.Provider>
);
};