Classy Store

Getting started

Install Classy Store, create a store, and read it in a React component.

Installation

bun add @codebelt/classy-store

Quick Start

1. Define a store class

counter.ts
export class Counter {
  count = 0;

  increment() {
    this.count++;
  }
}

2. Create a reactive store

stores.ts
import {createClassyStore, snapshot} from '@codebelt/classy-store';
import {Counter} from './counter';

export const counter = createClassyStore(new Counter());
snapshot(counter).count; // 0

3. Use in React components

CounterButton.tsx
import {useClassyStore} from '@codebelt/classy-store/react';
import {counter} from './stores';

export function CounterButton() {
  const count = useClassyStore(counter, (state) => state.count);
  return <button onClick={() => counter.increment()}>{count}</button>;
}

This shared instance is for a client-only app. For SSR or independent subtrees, scope the store to a request or provider.

Open the reactivity example →

Framework support and upgrades

For the upgrade from 0.10.x and framework support in 0.11.0, see the 0.11.0 release notes.

Upgrading from 0.7.x? Read the 0.8.0 upgrade guide for public API changes and persistence error handling. From 0.6.x or earlier, also follow the 0.7.0 upgrade guide.

All framework peer dependencies are optional — install only what your project uses:

FrameworkPeer DependencyImport
Reactreact ^18.0.0 || ^19.0.0@codebelt/classy-store/react
Vuevue ^3.2.0@codebelt/classy-store/vue
Sveltesvelte ^4.0.0 || ^5.0.0@codebelt/classy-store/svelte
Solid 2 (preview)solid-js 2.0.0-rc.18 (exact)@codebelt/classy-store/solid
Angular@angular/core ^22.0.0@codebelt/classy-store/angular

These ranges include stable releases within the listed majors and exclude untested future majors. Solid remains pinned to its exact tested prerelease. Use matching React/React DOM versions. Development dependencies stay pinned independently of the supported consumer ranges.

Packed compatibility checks cover React 18.0.0 and 19.0.0, Vue 3.2.0, and Svelte 4.0.0 and 5.0.0. React's existing 18.3.1/current-19 checks remain in the matrix. The Vue and Svelte checks reuse the focused input, timing, computed, list, and cleanup tests with each consumer's native compiler; CI runs them in Chromium.

Choose a guide

Section index

On this page