import { useChannelPreviewData } from "stream-chat-react-native";
type Props = {
channel: Channel;
client: StreamChat;
};
const CustomPreview = ({ channel, client }: Props) => {
const { lastMessage, muted, unread } = useChannelPreviewData(channel, client);
return (
<>
<Text>{lastMessage?.text ?? "No messages yet"}</Text>
{!muted && unread > 0 ? <Text>{unread}</Text> : null}
</>
);
};This is beta documentation for Stream Chat React Native SDK v9. For the latest stable version, see the latest version (v8)
.
useChannelPreviewData
Returns channel preview state (lastMessage, muted, and unread) for rendering list rows.
Best Practices
- Use this hook in custom
Previewcomponents rendered byChannelList. - Treat
lastMessageas optional and handle empty channels safely. - Avoid additional unread computations in render; use the hook output directly.
- Respect muted channels and avoid showing unread badges when muted.
- Keep expensive formatting outside the list item render path.
Usage
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| channel | Channel | Yes | Channel instance used to derive preview state and event bindings. |
| client | StreamChat | Yes | Active chat client used for read/unread event subscriptions. |
| forceUpdateOverride | number | No | Optional force-update counter override from channel-list context. |
Returns
| Name | Type | Description |
|---|---|---|
| lastMessage | LocalMessage | MessageResponse | Latest message used by the preview row. |
| muted | MuteStatus | Current mute status for the channel. |
| unread | number | Unread count for the current user. |