@fransek/statekit
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Statekit

Version Downloads Minzipped size

A tiny state management library for React.

  • Simple
  • Lightweight
  • First-class TypeScript support

Getting started

  1. Install the package:
npm i @fransek/statekit
  1. Create a store:
import { createStore } from "@fransek/statekit";

const store = createStore({ count: 0 }, (set) => ({
  increment: () => set((state) => ({ count: state.count + 1 })),
  decrement: () => set((state) => ({ count: state.count - 1 })),
  reset: () => set({ count: 0 }),
}));
  1. Use the store:
import { useStore } from "@fransek/statekit";
import { store } from "./store";

function Counter() {
  const {
    state: { count },
    actions: { increment, decrement, reset },
  } = useStore(store);

  return (
    <div>
      <div>{count}</div>
      <button onClick={decrement}>-</button>
      <button onClick={increment}>+</button>
      <button onClick={reset}>Reset</button>
    </div>
  );
}

Read the API docs.

Dependencies (0)

    Dev Dependencies (25)

    Package Sidebar

    Install

    npm i @fransek/statekit

    Weekly Downloads

    9

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    107 kB

    Total Files

    51

    Last publish

    Collaborators

    • fransek