
Product
Introducing Data Exports
Export Socket alert data to your own cloud storage in JSON, CSV, or Parquet, with flexible snapshot or incremental delivery.
@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
The npm package @blac/react receives a total of 24 weekly downloads. As such, @blac/react popularity was classified as not popular.
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
Export Socket alert data to your own cloud storage in JSON, CSV, or Parquet, with flexible snapshot or incremental delivery.

Research
/Security News
Bitwarden CLI 2026.4.0 was compromised in the Checkmarx supply chain campaign after attackers abused a GitHub Action in Bitwarden’s CI/CD pipeline.

Research
/Security News
Docker and Socket have uncovered malicious Checkmarx KICS images and suspicious code extension releases in a broader supply chain compromise.