import { useContext } from "react";
import { ChannelContext } from "stream-chat-react-native";
const { lastRead, reloadChannel, watcherCount } = useContext(ChannelContext);ChannelContext
ChannelContext is provided by Channel. If you are not familiar with the React Context API, see the React docs.
Best Practices
- Prefer
useChannelContextto avoid direct context wiring. - Avoid using
ChannelContextdeep in message rows to prevent expensive re-renders. - Use
markReadinstead of callingchannel.markRead()directly to benefit from throttling. - Check
loading/errorbefore rendering heavy channel UI. - Treat
readandmembersas read-only UI data; update via client/channel APIs.
Basic Usage
Consume ChannelContext in any child of Channel:
Alternatively, use the useChannelContext hook.
import { useChannelContext } from "stream-chat-react-native";
const { lastRead, reloadChannel, watcherCount } = useChannelContext();Avoid using ChannelContext at the message level; changes can re-render all messages and cause performance issues.
Value
channel
Channel instance from the Stream Chat client.
| Type |
|---|
| Channel |
enforceUniqueReaction
Limits reactions to one per user. Selecting a new reaction replaces the previous one (similar to iMessage).
| Type | Default |
|---|---|
| boolean | false |
disabled
True if channel is frozen and disableIfFrozenChannel is true.
| Type |
|---|
| Boolean |
error
True if any channel.query() call fails during initial load or pagination.
| Type |
|---|
| Error object | boolean |
giphyEnabled
True if Giphy is enabled on the channel type.
| Type |
|---|
| boolean |
hideDateSeparators
Hide inline date separators in MessageList.
| Type | Default |
|---|---|
| boolean | false |
hideStickyDateHeader
Note: Available in SDK version >= v3.9.0.
Hide the sticky date header in MessageList.
| Type | Default |
|---|---|
| boolean | false |
isAdmin
True if the current user has the admin role at app or channel level. See User Roles.
const isAdmin =
client?.user?.role === "admin" || channel?.state.membership.role === "admin";| Type |
|---|
| boolean |
isModerator
True if the current user has the moderator role at app or channel level. See User Roles.
const isModerator =
channel?.state.membership.role === "channel_moderator" ||
channel?.state.membership.role === "moderator";| Type |
|---|
| boolean |
isOwner
True if the current user has owner permissions for the channel type. See User Permission.
const isOwner = channel?.state.membership.role === "owner";| Type |
|---|
| boolean |
lastRead
Timestamp when the current user marked the channel as read (channel.markRead()).
| Type |
|---|
| Date |
loadChannelAroundMessage
Load the channel with messages around a specific message in history.
loadChannelAroundMessage({
messageId,
});| Type |
|---|
| function |
loading
True while the channel loads messages for the first time.
| Type |
|---|
| boolean |
LoadingIndicator
Renders a full-screen loading indicator when a channel is loading.
| Type | Default |
|---|---|
| ComponentType | LoadingIndicator |
markRead
Marks the channel as read for the current user. Internally calls channel.markRead() (throttled) if read events are enabled.
| Type |
|---|
| function |
maxTimeBetweenGroupedMessages
Maximum time (ms) between consecutive messages from the same user to keep them grouped.
| Type | Default |
|---|---|
| number | infinite |
members
Members of current channel. This value is received from backend when you query a channel, either using client.queryChannels() or channel.watch() API call.
client.queryChannels() or channel.watch() returns only up to 100 members of channel. So if you expect total number of members to be > 100, its better to use client.queryMembers() API endpoint separately to get the list of members.
Record<
string, // userId
{
banned?: boolean;
created_at?: string;
invite_accepted_at?: string;
invite_rejected_at?: string;
invited?: boolean;
is_moderator?: boolean;
role?: string;
shadow_banned?: boolean;
updated_at?: string;
user?: UserResponse<UserType>;
user_id?: string;
}
>;| Type |
|---|
| object |
read
Read statuses for channel members. Received from the backend via client.queryChannels() or channel.watch().
Record<
string, // userId
{
last_read: Date;
user: UserResponse<UserType>;
}
>;| Type |
|---|
| object |
reloadChannel
Reloads the channel at the most recent message. Resolves when reload completes.
| Type |
|---|
| () => Promise |
scrollToFirstUnreadThreshold
Minimum number of unread messages a channel should have in order to set the initial scroll position to first unread message. This value is only used when initialScrollToFirstUnreadMessage is set to true.
| Type | Default |
|---|---|
| number | 4 |
setLastRead
Setter for the lastRead state in Channel.
| Type |
|---|
(date: Date) => void |
setTargetedMessage
Setter for the targetedMessage state in Channel.
| Type |
|---|
(messageId: string) => void |
targetedMessage
ID of the currently highlighted message. Set when you load a channel around a message using loadChannelAroundMessage.
| Type |
|---|
| string |
watchers
Watchers of current channel. This value is received from backend when you query a channel, either using client.queryChannels() or channel.watch() API call.
client.queryChannels() or channel.watch() returns only up to 100 watchers for channel. So if you expect total number of watchers to be > 100, you should request them explicitly using Channel Pagination
Record<
string, // string
UserResponse<UserType>
>;| Type |
|---|
| object |
watcherCount
Total users currently watching the channel.
| Type |
|---|
| number |
EmptyStateIndicator
Renders when the channel has no messages.
| Type | Default |
|---|---|
| ComponentType | EmptyStateIndicator |
NetworkDownIndicator
Renders an indicator at the top of the channel when the network/connection is down.
| Type | Default |
|---|---|
| ComponentType | NetworkDownIndicator |
- Best Practices
- Basic Usage
- Value
- channel
- enforceUniqueReaction
- disabled
- error
- giphyEnabled
- hideDateSeparators
- hideStickyDateHeader
- isAdmin
- isModerator
- isOwner
- lastRead
- loadChannelAroundMessage
- loading
- LoadingIndicator
- markRead
- maxTimeBetweenGroupedMessages
- members
- read
- reloadChannel
- scrollToFirstUnreadThreshold
- setLastRead
- setTargetedMessage
- targetedMessage
- watchers
- watcherCount
- EmptyStateIndicator
- NetworkDownIndicator