dharma-react
v0.9.0
Published
React bindings for Dharma
Maintainers
Readme
dharma-react
dharma-react provides React bindings for dharma-core.
Getting started
- Install the packages:
npm install dharma-core dharma-react
# or
pnpm add dharma-core dharma-react
# or
yarn add dharma-core dharma-react- Create a store:
import { createStore } from "dharma-core";
export const store = createStore({
initialState: { count: 0 },
actions: ({ set }) => ({
increment: () => set((state) => ({ count: state.count + 1 })),
decrement: () => set((state) => ({ count: state.count - 1 })),
}),
});
export const { increment, decrement } = store.actions;- Use the store:
import { useStore } from "dharma-react";
import { decrement, increment, store } from "./store";
function Counter() {
const { count } = useStore(store);
return (
<div>
<div>{count}</div>
<button onClick={decrement}>-</button>
<button onClick={increment}>+</button>
</div>
);
}