Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

@blac/react

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blac/react

React bindings for BlaC — useBloc hook with automatic re-render optimization

latest
Source
npmnpm
Version
2.0.12
Version published
Maintainers
1
Created
Source

@blac/react

React bindings for BlaC — useBloc hook with proxy-based automatic re-render optimization.

Documentation · npm

Installation

pnpm add @blac/react @blac/core

Requires React 18+ (useSyncExternalStore).

Quick Start

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>
  );
}

useBloc

const [state, bloc, ref] = useBloc(MyBloc, options?);

Returns: [state, bloc, ref]

  • state — current state snapshot (proxied for auto-tracking)
  • bloc — bloc instance for calling methods
  • ref — internal component ref (advanced usage)

Tracking Modes

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 });

Options

OptionTypeDescription
autoTrackbooleanEnable proxy-based auto-tracking (default: true)
dependencies(state, bloc) => unknown[]Manual dependency selector
instanceIdstring | numberUse a named instance instead of the shared singleton
onMount(bloc) => voidCalled when component mounts
onUnmount(bloc) => voidCalled when component unmounts

Instance Sharing

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

Configuration

import { configureBlacReact } from '@blac/react';

configureBlacReact({ autoTrack: true });

Testing

import { renderWithBloc } from '@blac/react/testing';

See the testing docs for details.

License

MIT

Keywords

react

FAQs

Package last updated on 31 Mar 2026

Did you know?

Socket

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.

Install

Related posts