Skip to main content
Version: v11 (legacy)

ChannelStateContext

The ChannelStateContext is a one of the context providers exposed in the Channel component and is consumable by all of the Channel children components. The context provides all the state properties and logic for a channel, and you can access these by calling the useChannelStateContext custom hook.

Basic Usage

Pull values from context with our custom hook:

const { channel, watchers } = useChannelStateContext();

Values

acceptedFiles

A list of accepted file upload types.

Type
string[]

channel

The currently active StreamChat channel instance to be loaded into the Channel component and referenced by its children.

Type
object

channelCapabilities

The allowed channel permissions for the currently connected user.

Type
object

channelConfig

The configurations object for the currently active channel.

Type
object

dragAndDropWindow

If true, chat users will be able to drag and drop file uploads to the entire channel window.

TypeDefault
booleanfalse

debounceURLEnrichmentMs:

Number of milliseconds to debounce firing the URL enrichment queries when typing. The default value is 1500(ms). See the guide Link Previews in Message Input for more.

TypeDefault
number1500

enrichURLForPreview

A global flag to toggle the URL enrichment and link previews in MessageInput. By default, the feature is disabled. It can be overridden on Thread and MessageList level through additionalMessageInputProps or directly on MessageInput level through urlEnrichmentConfig prop.

TypeDefault
booleanfalse

error

Error object (if any) in loading the channel, otherwise null.

Type
object

findURLFn

Custom function to identify URLs in a string for later generation of link previews. See the guide Link Previews in Message Input for more.

Type
(text: string) => string[]

giphyVersion

The giphy version to use when displaying giphies.

Type
'original' | 'fixed_height' | 'fixed_height_still' | 'fixed_height_downsampled' | 'fixed_width' | 'fixed_width_still' | 'fixed_width_downsampled'

imageAttachmentSizeHandler

A custom function to provide size configuration for image attachments

Type
(a: Attachment, e: HTMLElement) => ImageAttachmentConfiguration

hasMore

If the channel has more, older, messages to paginate through.

Type
boolean

hasMoreNewer

If the channel has more, newer, messages to paginate through.

Type
boolean

highlightedMessageId

Value is used internally for jump-to-message logic. Once the user "jumped" to the message, the message with the given ID is highlighted by manipulating its styles attribute.

Type
string

loading

Boolean for the channel loading state.

Type
boolean

loadingMore

Boolean for the channel loading more messages.

Type
boolean

loadingMoreNewer?

Flag signalling whether newer messages are being loaded as the user scrolls down in the message list. Used internally by VirtualizedMessageList.

Type
boolean

maxNumberOfFiles

The maximum number of attachments allowed per message, defaults to the Stream Chat API maximum.

TypeDefault
number10

members

Members of this channel (members are permanent, watchers are users who are online right now).

Type
object[]

messages

Array of message objects.

Type
object[]

multipleUploads

Whether to allow multiple attachment uploads on a message.

TypeDefault
booleantrue

mutes

An array of muted users for a channel.

Type
object[]

notifications

Temporary notifications added to the MessageList on specific user/message actions.

Type
{id: string, text: string, type: 'success' | 'error'}[]

onLinkPreviewDismissed

Custom function to react to link preview dismissal. See the guide Link Previews in Message Input for more.

Type
(linkPreview: LinkPreview) => void

channelUnreadUiState

The read state maintained for use by components representing channel unread state (for example UnreadMessagesSeparator, UnreadMessagesNotification).

PropertyTypeDescription
last_readDateDate when the channel was marked read the last time.
unread_messagesnumberThe count of unread messages in a given channel. Unread count refers only to foreign (not own) unread messages.
first_unread_message_idstring or undefinedThe ID of the message that was marked unread (notification.mark_unread event). The value is available only when a message is marked unread. Therefore, cannot be relied on to place unread messages UI.
last_read_message_idstring or undefinedThe ID of the message preceding the first unread message.
Type
ChannelUnreadUiState

pinnedMessages

The messages that are pinned in the channel.

Type
object[]

quotedMessage

An inline message reply to another message.

Type
object

read

The read state for each channel member.

Type
object

suppressAutoscroll

Flag signalling whether the scroll to the bottom is prevented. Used internally by MessageList and VirtualizedMessageList components.

Type
boolean

shouldGenerateVideoThumbnail

You can turn on/off thumbnail generation for video attachments

Type
boolean

thread

The parent message for a thread, if there is one, otherwise null.

Type
object

threadHasMore

Boolean showing if there are more messages available in current active thread, set to false when the end of pagination is reached.

Type
boolean

threadLoadingMore

If the thread is currently loading more messages.

Type
boolean

threadMessages

Array of messages within a thread.

Type
object[]

threadSuppressAutoscroll

Flag signalling whether the scroll to the bottom is prevented in thread. Used internally by MessageList and VirtualizedMessageList components.

Type
boolean

videoAttachmentSizeHandler

A custom function to provide size configuration for video attachments

Type
(a: Attachment, e: HTMLElement) => VideoAttachmentConfiguration

watcherCount

The number of watchers on the channel.

Type
number

watchers

An array of users who are currently watching the channel.

Type
object[]

watcher_count

The number of watchers on the channel.

Type
number

Did you find this page helpful?