import { useMessageListContext } from "stream-chat-react";
export const CustomComponent = () => {
const { listElement, scrollToBottom } = useMessageListContext();
// component logic ...
return {
/* rendered elements */
};
};This is documentation for Stream Chat React SDK v13, which is no longer actively maintained. For up-to-date documentation, see the latest version (v14).
MessageListContext
The context value is provided by MessageListContextProvider, which wraps the content rendered by MessageList. It exposes API used by default and custom components. Components that can consume MessageListContext include:
EmptyStateIndicator- rendered when there are no messages in the channel. Thecomponent can be customized.LoadingIndicator- rendered while loading more messages to the channel. Thecomponent can be customized.MessageListNotifications- component rendering application notifications. Thecomponent can be customized.MessageNotification- component used to display a single notification message inMessageListNotifications. Thecomponent can be customized.TypingIndicator- component indicating that another user is typing a message in a given channel. Thecomponent can be customized.Messageand its children - component that renders a message. Thecomponent can be customized.DateSeparator- component rendered to separate messages posted on different dates. Thecomponent can be customized.MessageSystem- component to display system messages in the message list. Thecomponent can be customized.HeaderComponent- component to be displayed before the oldest message in the message list. Thecomponent can be customized.UnreadMessagesNotification- custom UI component that indicates a user is viewing unread messages. It disappears once the user scrolls toUnreadMessagesSeparator. Thecomponent can be customized.UnreadMessagesSeparator- component to be displayed before the oldest message in the message list. Thecomponent can be customized.
Best Practices
- Use context values instead of querying DOM elements directly.
- Keep custom components aligned with the default loading/empty states.
- Use
listElementandscrollToBottomfor custom scrolling UX. - Avoid heavy logic inside list-level components to keep renders smooth.
- Treat notification components as transient UI and keep them lightweight.
Basic Usage
Pull the value from context with our custom hook:
Values
listElement
The scroll container that renders messages and the typing indicator. You can use it to implement custom scroll behavior.
| Type |
|---|
HTMLDivElement | null |
scrollToBottom
Scrolls the listElement to the bottom.
| Type |
|---|
() => void |