Skip to content

API reference / @chanx-js/client / react / useChannel

Function: useChannel() ​

ts
function useChannel<D>(descriptor, options?): UseChannelResult<ToServerOf<D>, ToClientOf<D>>;

Defined in: packages/client/src/react/useChannel.ts:46

Open (or join) a channel's connection for the lifetime of the component.

On a channel carrying topics, components with the same params share one socket, which closes when the last of them unmounts. A plain channel gets a socket per component unless share: true. Changing params, queryParams, protocols, share or enabled reconnects; changing handlers does not.

Type Parameters ​

Type Parameter
D extends ChannelDescriptor<any, any, any, any>

Parameters ​

ParameterType
descriptorD
optionsUseChannelOptions<AddressOf<D>, ToClientOf<D>>

Returns ​

UseChannelResult<ToServerOf<D>, ToClientOf<D>>

MIT licensed