Skip to content

Search v2 documentation only

BroadcastProvider

<BroadcastProvider channelName="app" options={{ namespace: 'v1' }}>
<App />
</BroadcastProvider>
Prop Type Required Description
channelName string yes Channel name. Combined with options.namespace when one is set.
options BroadcastOptions no Identical to the hook’s options, including sourceName, registeredTypes, onMessage, and telemetry.
children ReactNode yes Subtree that shares the channel.
const actions = useBroadcastProvider();

Returns the BroadcastActions shared by the nearest BroadcastProvider. Throws when called outside one.

Pass the same message map to the provider and the context hook:

<BroadcastProvider<AuthEvents> channelName="auth">
<App />
</BroadcastProvider>;
const { postMessage } = useBroadcastProvider<AuthEvents>();

options, postMessage, onMessage and the getters are then checked against the map. Types only; omitting the generic keeps the loose behavior. See the Typed Channels recipe.

The same rules as the hook apply: the tab ignores its own messages, messages is an event log (not current state), and a tab opened later does not receive earlier messages.