Skip to content

Quick Start

  1. Install the package:

    Terminal window
    npm install dharma-core
  2. Create a store:

    import { createStore } from "dharma-core";
    const store = createStore({
    initialState: { count: 0 },
    actions: ({ set }) => ({
    increment: () => set((state) => ({ count: state.count + 1 })),
    decrement: () => set((state) => ({ count: state.count - 1 })),
    }),
    });
    const { increment, decrement } = store.actions;
  3. Subscribe to the store and update its state by calling actions:

    // Subscribe to state changes
    const unsubscribe = store.subscribe((state) => console.log(state));
    // Update the state
    increment();
    // { count: 1 }
    decrement();
    // { count: 0 }
    unsubscribe();