Quick Start
State Management in 2 Minutes
Learn how to create and use a store with qortex-store.
qortex-store provides a simple, type-safe API for managing application state. It works anywhere — Node, browser, vanilla JS.
1. Create a Store
Define your state and actions using `createStore`:
1. Create a Store
import { createStore } from 'qortex-store';const counterStore = createStore((set, get) => ({count: 0,increment: () => set({ count: get().count + 1 }),decrement: () => set((state) => ({ count: state.count - 1 })),reset: () => set({ count: 0 }),}));
2. Read and Update State
Use `get` and `set` from anywhere:
2. Read and Update State
// Read statecounterStore.get().count; // 0// Update via actionscounterStore.get().increment();counterStore.get().count; // 1// Or use set directlycounterStore.set({ count: 42 });
3. Subscribe to Changes
Listen for state changes and clean up when done:
3. Subscribe to Changes
const unsub = counterStore.subscribe((state, prev) => {console.log('count:', prev.count, '→', state.count);});// Later, stop listeningunsub();