Skip to content

Getting Started

Install

For vanilla projects:

sh
npx jsr add @kin-store/core
sh
pnpm dlx jsr add @kin-store/core
sh
yarn dlx jsr add @kin-store/core
sh
deno add jsr:@kin-store/core

For React projects (@kin-store/core is included):

sh
npx jsr add @kin-store/react
sh
pnpm dlx jsr add @kin-store/react
sh
yarn dlx jsr add @kin-store/react
sh
deno add jsr:@kin-store/react

To add official plugins:

sh
npx jsr add @kin-store/plugins
sh
pnpm dlx jsr add @kin-store/plugins
sh
yarn dlx jsr add @kin-store/plugins
sh
deno add jsr:@kin-store/plugins

Quick start

Create a store, write plain functions, done:

ts
import { createStore } from '@kin-store/core';

type TodoState = { todos: string[]; status: 'idle' | 'loading' };

const store = createStore({ todos: [], status: 'idle' } as TodoState);

function addTodo(text: string): void {
  store.setState((s) => ({ ...s, todos: [...s.todos, text] }));
}

addTodo('Buy groceries');
console.log(store.getState());
// { todos: ['Buy groceries'], status: 'idle' }

When your app grows, move logic into the store with .use():

ts
import { withPlugins } from '@kin-store/core';
import { persist, history } from '@kin-store/plugins';

const store = withPlugins({ todos: [], status: 'idle' } as TodoState)
  .use('persist', persist({ key: 'todos' }))
  .use('history', history())
  .use({
    methods: (store) => ({
      addTodo(text: string): void {
        store.setState((s) => ({ ...s, todos: [...s.todos, text] }));
      },
    }),
  });

store.addTodo('Buy groceries');
store.history.undo();
await store.persist.hydrate();

Each .use() adds capability — not a nesting level. The store grows with you.

What's next

Released under the MIT License.