useChannelPreviewData

Returns channel preview state (lastMessage, muted, pinned, and unread) for rendering list rows.

Best Practices

  • Use this hook in custom ChannelPreview components rendered by ChannelList.
  • Treat lastMessage as 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

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}
    </>
  );
};

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 boolean Whether the channel is currently muted.
pinned boolean Whether the channel is pinned for the current user.
unread number Unread count for the current user.
Add Chat to my app: getstream.io/SKILL.md

The fastest way to build with Stream. Start a new project or improve an existing one. Full CLI and documentation integration out of the box.


Ask your agent:

/stream Build me a Social App with Feeds and Moderation.
/stream Any livestream calls running?
/stream Chat React Native v9: <Your Question>