Skip to content

Search v1.11.2 archive only

Getting started with v1.11.2

Terminal window
npm install react-broadcast-sync@1.11.2

The package declares React and React DOM >=16.8.0 as peers and uses the browser’s native BroadcastChannel. It does not add a cross-origin or server transport.

import { useBroadcastChannel } from 'react-broadcast-sync';
export default function Greeting() {
const { messages, postMessage, error } = useBroadcastChannel('greetings', {
telemetry: false,
});
return (
<section>
<button onClick={() => postMessage('greeting', { text: 'Hello!' })}>Send</button>
{error && <p role="alert">{error}</p>}
{messages.map(msg => (
<p key={msg.id}>{msg.message.text}</p>
))}
</section>
);
}

Open the same-origin app in two tabs. Click Send in tab A; tab B receives the message. Tab A’s local messages does not receive its own send. The generated source name should stay unique per tab; do not hardcode the same source name in every tab.

telemetry: false explicitly disables the historical package telemetry. Unlike v2, 1.11.2 otherwise enables it by default. See historical telemetry.

Default batching buffers sends for up to 20 ms. The receiver accepts non-expired, permitted, non-duplicate IDs from other sources. A tab opened after the send does not recover it. messages is a local received-message log, not a stored current value. Full v1 API.

The archive keeps version-specific behavior but corrects misleading prose against that version’s code. It is not a verbatim reproduction of the historical README.