useBroadcastChannel

Reactive BroadcastChannel API.

Example

Basic Usage

Please open this page in at least two tabs

message:""

API

const {  isSupported,data, error,  postMessage, close,} = useBroadcastChannel(channelName, options)
const {  isSupported,data, error,  postMessage, close,} = useBroadcastChannel(channelName, options)

Params

PropertyDescriptionTypeDefault
channelNameRequired, channel namestring-
optionsoptionOptions-

Options

PropertyDescriptionTypeDefault
onMessageFired when a message arrives on the channel.(e: MessageEvent) => void-
onMessageErrorFired when a message arrives that can't be deserialized.(e: MessageEvent) => void-

Result

Property说明类型
isSupportedSupport or not BroadcastChannelAccessor<boolean>
dataThe latest message data currently received.Accessor<any>
errorChannel error messageAccessor<MessageEvent | null>
channelBroadcastChannel Instance() => BroadcastChannel | null
postMessagepost message (data: any) => void
closeclose current channel() => void