|
| 1 | +--- |
| 2 | +id: message_list_context |
| 3 | +sidebar_position: 8 |
| 4 | +title: MessageListContext |
| 5 | +--- |
| 6 | + |
| 7 | +The context value is provided by `MessageListContextProvider` which wraps the contents rendered by [`MessageList`](../core-components/message-list.mdx). It exposes API that the default and custom components rendered by `MessageList` can take advantage of. The components that can consume the context are: |
| 8 | + |
| 9 | +- `EmptyStateIndicator` - rendered when there are no messages in the channel. The [`component can be customized`](./component-context.mdx#emptystateindicator). |
| 10 | +- `LoadingIndicator` - rendered while loading more messages to the channel. The [`component can be customized`](./component-context.mdx#loadingindicator). |
| 11 | +- `MessageListNotifications` - component rendering application notifications. The [`component can be customized`](./component-context.mdx#messagelistnotifications). |
| 12 | +- `MessageNotification` - component used to display a single notification message in `MessageListNotifications`. The [`component can be customized`](./component-context.mdx#messagenotification). |
| 13 | +- `TypingIndicator` - component indicating that another user is typing a message in a given channel. The [`component can be customized`](./component-context.mdx#typingindicator). |
| 14 | +- `Message` and its children - component to render a message. The [`component can be customized`](./component-context.mdx#message). |
| 15 | +- `DateSeparator` - component rendered to separate messages posted on different dates. The [`component can be customized`](./component-context.mdx#dateseparator). |
| 16 | +- `MessageSystem` - component to display system messages in the message list. The [`component can be customized`](./component-context.mdx#messagesystem). |
| 17 | +- `HeaderComponent` - component to be displayed before the oldest message in the message list. The [`component can be customized`](./component-context.mdx#headercomponent). |
| 18 | + |
| 19 | +## Basic Usage |
| 20 | + |
| 21 | +Pull the value from context with our custom hook: |
| 22 | + |
| 23 | +```jsx |
| 24 | +import { useMessageListContext } from 'stream-chat-react'; |
| 25 | + |
| 26 | +export const CustomComponent = () => { |
| 27 | + const { listElement, scrollToBottom } = useMessageListContext(); |
| 28 | + // component logic ... |
| 29 | + return( |
| 30 | + {/* rendered elements */} |
| 31 | + ); |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +## Value |
| 36 | + |
| 37 | +### listElement |
| 38 | + |
| 39 | +The scroll container within which the messages and typing indicator are rendered. You may want to perform scroll-to-bottom operations based on the `listElement`'s scroll state. |
| 40 | + |
| 41 | +| Type | |
| 42 | +|--------------------------| |
| 43 | +| `HTMLDivElement \| null` | |
| 44 | + |
| 45 | +### scrollToBottom |
| 46 | + |
| 47 | +Function that scrolls the `listElement` to the bottom. |
| 48 | + |
| 49 | +| Type | |
| 50 | +|--------------| |
| 51 | +| `() => void` | |
0 commit comments