ChannelHooks
A channel bound to a name and message map: typed hooks with no per-call generics.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
M extends MessageMap |
Properties
Section titled “Properties”get: () => Channel<M>;The underlying channel instance (the same one the hooks use) — for non-React code.
Returns
Section titled “Returns”Channel<M>
useMessage
Section titled “useMessage”useMessage: <K>(type, handler) => void;Subscribe to one message type. Same contract as the standalone
useMessage: the handler is kept fresh without resubscribing.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
K extends string |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
type | K |
handler | (payload, meta) => void |
Returns
Section titled “Returns”void
useSend
Section titled “useSend”useSend: () => <K>(type, payload, options?) => void;The channel’s post function (stable identity).
Returns
Section titled “Returns”<K>( type, payload, options?): void;Fire-and-forget to every other tab/window/worker on this origin.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
K extends string |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
type | K |
payload | M[K] |
options? | PostOptions |
Returns
Section titled “Returns”void