<Counter /> renders 1
count
State management for React & TypeScript v2 beta
BlaC puts state and business logic in plain TypeScript classes. Components read what they need and call methods. A component re-renders when a value it read changes, and state changes it didn't read never reach it.
pnpm add @blac/core @blac/react <Counter /> renders 1
count
<Avatar /> renders 1
user.name
<Toolbar /> renders 1
user.nametheme
<Cart /> renders 1
cart.items
Real useBloc, real renders. Press a jack: only what reads it lights up.
Quick look
No store to configure, no provider around your app, no reducers or selectors. The class owns the state and the methods that change it. The component renders state and calls methods.
import { Cubit } from '@blac/core';import { useBloc } from '@blac/react';
class CounterCubit extends Cubit<{ count: number }> { constructor() { super({ count: 0 }); } increment = () => this.emit({ count: this.state.count + 1 });}
function Counter() { const [state, counter] = useBloc(CounterCubit); return <button onClick={counter.increment}>{state.count}</button>;}How it works
Each one links to its reference page. The chapters take them apart step by step, with BlaC running on the stage beside the text.
Reading state.user.name during render subscribes the component to that value and nothing else. Change the email and it stays put. There are no selectors to write and no dependency arrays to keep in sync.
State, rules and async work live in a class with no React in it. The component reads state and calls methods. The class runs in a plain unit test, and the API behind it can change without touching the UI.
The first component that uses a bloc creates it, and the last one to unmount disposes it. Instances are shared by default. Key them with args, give each mount its own with isolated, or keep one around with keepAlive.
A getter can read another bloc’s state through .track(). Components that read the getter re-render when either bloc changes it, with no second useBloc call.
Packages
@blac/core Cubit, the instance registry and path tracking: state, methods, getters and lifecycle, with no React dependency.
React@blac/react useBloc records what each render reads and re-renders on exactly that. Testing helpers included.
Async data@blac/async Resources and mutations kept in state: status, latest request wins, abort on release, tag-based invalidation.
PluginsPlugins DevTools, persistence (IndexedDB, Web Storage) and logging attach to every bloc without touching a component.
Testing
A bloc is a class: construct it, call methods, check its state. No DOM, no providers, no mocked hooks. For
component tests, renderWithBloc mounts a component with the state you choose.
import { it, expect } from 'vitest';import { CartCubit } from './CartCubit';
it('totals the cart', () => { const cart = new CartCubit(); cart.add({ id: 'jack', price: 12 }); cart.add({ id: 'cable', price: 4 }); expect(cart.total).toBe(16);});Start with the first chapter, or go straight to the reference.