Skip to main content

Channel

The Channel component is a React Context provider that wraps all of the logic, functionality, and UI for an individual chat channel. It provides three separate contexts to its children:

  • ChannelStateContext - stateful data (ex: activeChannel)
  • ChannelActionContext - action handlers (ex: sendMessage or openThread)
  • ComponentContext - custom component UI overrides (ex: Input or Message)

Basic Usage

The Channel component does not inject any UI, so its implementation is fairly simple.The Channel component listens for the channel.activeChange event and captures the latest activeChannel for its child components to fetch via ChannelStateContext.

tip

If your channelList list is empty, you can create a chat room in createChannel.

Custom Input

In the channel component, you can pass in an Input component with custom styles and functionality, where you can get the sendMessage method through the useMessageInputContext method.

tip

The Input property of 'channel' has a lower priority than the Input property of 'MessageInput', and it is recommended to pass in as the Input property of 'MessageInput'.

 const { sendMessage } = useMessageInputContext();

Custom Message

If you want to display a custom list of messages, you can pass the custom Message component as a parameter in the channel, and the MessageList will iterate through the Message component, and you can get the corresponding message in the component via the useMessageContext method.

const { message } = useMessageContext();

How to use custom Component Example

useChannelStateContext

Any child of the Channel component has access to the channelStateContext and componentContext. Each React Context in the component library can be accessed with one of our custom hooks, which must be imported individually.

const { activeChannel } = useChannelStateContext();

useComponentContext

const { Message, Input } = useComponentContext();

Api

Channel

The properties of the Channel are described as follows:

PropertyDescriptionTypeDefaultrequired
Inputset your custom Input componentReact.ComponentType-false
Messageset your custom Message componentReact.ComponentType-false

useChannelStateContext data

PropertyDescriptionTypeDefaultrequired
activeChannelcurrent active channelChannelItemType--

useComponentContext data

PropertyDescriptionTypeDefaultrequired
Inputset custom MessageInput componentReact.Component--
Messageset custom Message componentReact.Component--