Getting started
Install Classy Store, create a store, and read it in a React component.
Installation
bun add @codebelt/classy-storeQuick Start
1. Define a store class
export class Counter {
count = 0;
increment() {
this.count++;
}
}2. Create a reactive store
import {createClassyStore, snapshot} from '@codebelt/classy-store';
import {Counter} from './counter';
export const counter = createClassyStore(new Counter());
snapshot(counter).count; // 03. Use in React components
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.
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:
| Framework | Peer Dependency | Import |
|---|---|---|
| React | react ^18.0.0 || ^19.0.0 | @codebelt/classy-store/react |
| Vue | vue ^3.2.0 | @codebelt/classy-store/vue |
| Svelte | svelte ^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
- React tutorial, scoped stores, server rendering, and Next.js
- Vue, Svelte, Solid 2 preview, and Angular
- API reference and store patterns
- Persistence, undo and redo, property subscriptions, and Redux DevTools
Section index
- Choosing an API
- Package entry points
- API Reference
createClassyStore(instance)useClassyStore(store, selector?, options?)useHistoryStatus(history)usePersistStatus(handle)prepareStoreForHydration(store)useLocalStore(factory)createStoreHook(store)snapshot(store)subscribe(store, callback, options?)shallowEqual(a, b)reactiveMap<K, V>(initial?)reactiveSet<T>(initial?)Snapshot<T>- Collections (
@codebelt/classy-store/collections) - Utilities (
@codebelt/classy-store/utils) persist(store, options)devtools(store, options?)subscribeKey(store, key, callback, options?)withHistory(store, options?)- React Compiler compatibility
- When to use each mode
- Patterns
- Multiple stores
- Class inheritance
- Nested object mutations
- Array operations
- Computed getters (automatic memoization)
- Working with Date and RegExp
- Features
- Comparison with other libraries
- Vision
- Acknowledgements
