const { client, setActiveChannel } = useChatContext();ChatContext
ChatContext is provided by the Chat component. All SDK components under Chat can access it via the useChatContext hook.
Best Practices
- Access context only inside children of
Chatto avoid null/undefined values. - Prefer
setActiveChannelover manual prop wiring when switching channels. - Use
channelsQueryStateto drive loading and error UI consistently. - Keep context consumers narrow to avoid unnecessary re-renders.
- Treat
customClassesandthemeas read-only configuration in context consumers.
Basic Usage
Pull values from ChatContext with our custom hook:
Values
client
The value is forwarded to the context from the Chat component prop client.
| Type |
|---|
StreamChat |
channel
The currently active channel, which powers the Channel component.
| Type |
|---|
| Channel |
channelsQueryState
Exposes API that:
- indicates which channel query is in progress in
ChannelListviaqueryInProgress - allows updates via
setQueryInProgress - tracks query errors via
error - allows updates via
setError
queryInProgress values:
uninitialized- before the first queryreload- initial page load in progressload-more- loading the next pagenull- no query in progress after at least one page loaded
| Type |
|---|
ChannelsQueryState |
closeMobileNav
Closes the mobile navigation.
| Type |
|---|
() => void |
customClasses
Forwarded from the Chat prop customClasses.
| Type |
|---|
CustomClasses |
getAppSettings
Callback to fetch app settings (includes image and file upload config).
| Type |
|---|
() => Promise<AppSettingsAPIResponse> |
latestMessageDatesByChannel
Map of channel IDs to the date of the user’s latest message. Used to determine slow mode countdown.
| Type |
|---|
| { [key: string]: Date } |
mutes
Users muted by the connected user.
| Type |
|---|
| Mute[] |
navOpen
Whether the mobile nav is open at mobile breakpoints.
| Type | Default |
|---|---|
| boolean | true |
openMobileNav
Opens the mobile navigation.
| Type |
|---|
() => void |
setActiveChannel
Sets the active channel. Used by ChannelList to switch channels, and can be overridden via context.
| Type |
|---|
(newChannel?: Channel, watchers?: { limit?: number; offset?: number }) => void |
theme
Forwarded from the Chat prop theme.
| Type |
|---|
| string |
useImageFlagEmojisOnWindow
Forwarded from the Chat prop useImageFlagEmojisOnWindows.
| Type | Default |
|---|---|
| boolean | false |