
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
@blac/react
Advanced tools
React bindings for BlaC — useBloc hook with automatic re-render optimization
React bindings for BlaC — useBloc hook with proxy-based automatic re-render optimization.
pnpm add @blac/react @blac/core
Requires React 18+ (useSyncExternalStore).
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 });
decrement = () => this.emit({ count: this.state.count - 1 });
}
function Counter() {
const [state, counter] = useBloc(CounterCubit);
return (
<div>
<p>Count: {state.count}</p>
<button onClick={counter.increment}>+</button>
<button onClick={counter.decrement}>-</button>
</div>
);
}
const [state, bloc, ref] = useBloc(MyBloc, options?);
Returns: [state, bloc, ref]
state — current state snapshot (proxied for auto-tracking)bloc — bloc instance for calling methodsref — internal component ref (advanced usage)Auto-tracking (default): Only re-renders when accessed properties change.
const [state] = useBloc(UserBloc);
return <h1>{state.name}</h1>; // only re-renders when name changes
Manual dependencies: Explicit dependency array (disables auto-tracking).
const [state] = useBloc(CounterCubit, {
dependencies: (state) => [state.count],
});
No tracking: Re-renders on every state change.
const [state] = useBloc(MyBloc, { autoTrack: false });
| Option | Type | Description |
|---|---|---|
autoTrack | boolean | Enable proxy-based auto-tracking (default: true) |
dependencies | (state, bloc) => unknown[] | Manual dependency selector |
instanceId | string | number | Use a named instance instead of the shared singleton |
onMount | (bloc) => void | Called when component mounts |
onUnmount | (bloc) => void | Called when component unmounts |
By default, all components using useBloc(MyBloc) share the same instance. Use instanceId for separate instances:
useBloc(EditorCubit, { instanceId: 'editor-1' }); // instance A
useBloc(EditorCubit, { instanceId: 'editor-2' }); // instance B
import { configureBlacReact } from '@blac/react';
configureBlacReact({ autoTrack: true });
import { renderWithBloc } from '@blac/react/testing';
See the testing docs for details.
MIT
FAQs
React bindings for BlaC — useBloc hook with automatic re-render optimization
We found that @blac/react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.