Skip to content

Search v1.11.2 archive only

v1.11.2 provider

The context provider shares one hook connection and result with its descendants. It does not create a different transport or add persistence.

import { BroadcastProvider, useBroadcastProvider } from 'react-broadcast-sync';
export default function App() {
return (
<BroadcastProvider channelName="notifications" options={{ telemetry: false }}>
<NotificationBar />
</BroadcastProvider>
);
}
function NotificationBar() {
const { messages } = useBroadcastProvider();
return (
<div>
{messages.map(msg => (
<p key={msg.id}>{msg.message.text}</p>
))}
</div>
);
}
Prop Required Meaning
channelName yes Shared channel name.
options no V1.11.2 BroadcastOptions, including the historical telemetry opt-out.
children yes Descendant components.

useBroadcastProvider() outside a BroadcastProvider throws. Consumers under the same provider share state; separate providers or standalone hooks own separate connections. The v1 message API semantics still apply.

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.