MessageContext

MessageContext is provided by Message. If you are not familiar with the React Context API, see the React docs.

Best Practices

  • Use useMessageContext for consistent access and typings.
  • Keep message-level logic local; avoid reaching into channel state here.
  • Use actionsEnabled and canModifyMessage to gate UI actions.
  • Attach contextMenuAnchorRef in custom MessageItemView layouts when you need to control the long-press overlay anchor.
  • Avoid heavy computations in message contexts to prevent list jank.
  • Treat attachment arrays as read-only and render them efficiently.

Basic Usage

Consume MessageContext in any child of Message:

import { useContext } from "react";
import { MessageContext } from "stream-chat-react-native";

const { contextMenuAnchorRef, isMyMessage, message, files } =
  useContext(MessageContext);

Alternatively, use the useMessageContext hook.

import { useMessageContext } from "stream-chat-react-native";

const { contextMenuAnchorRef, isMyMessage, message, files } =
  useMessageContext();

Values

ValueDescriptionType
actionsEnabledSet to true when message.type === 'regular' && message.status === 'received'.boolean
alignmentSets whether the message aligns left or right in the list. Defaults to 'right'.enum('right', 'left')
contextMenuAnchorRefRef for the subview that should anchor the long-press context menu overlay items. Attach it inside custom MessageItemView implementations when you want the overlay to align to the bubble view or another specific subview instead of the full row.react ref
dismissOverlayDismisses any open message overlay.() => void
filesThe files attached to a message.array
groupStylesPosition of the message within a group of consecutive messages from the same user. Use groupStyles to style messages based on position (for example, avatars show only on the last message).array of enum('top', 'bottom', 'middle', 'single')
handleActionSends an attachment action on a message (for example, Giphy Shuffle/Cancel/Send).(name: string, value: string) => void
handleToggleReactionCallback function for toggling reaction from reaction selector.(reactionType: string) => Promise<void>
hasReactionsTrue if the message has at least one reaction.boolean
messageHasOnlySingleAttachmentWhether or not message has only a single attachment.boolean
imagesArray of image attachments on the message.array
isMessageAIGeneratedFactory function that determines whether a message is AI-generated.function
isMyMessageTrue if the message was sent by the current user.boolean
lastGroupMessageWhether or not this is the last message in a group of messages.boolean
messageMessage object.Message type
messageContentOrderOrder of message content. Example: ['quoted_reply', 'attachments', 'file', 'gallery', 'text'].array
onLongPressDefault long press handler for message UI.function
onlyEmojisTrue if the message text contains only emojis.boolean
onOpenThreadHandler function for "Thread Reply" action.function
onPressDefault press handler for message UI.function
onPressInDefault pressIn handler for message UI.function
otherAttachmentsAll attachments except file and image.array
reactionsReactions added to the message.array
readByRead count/state of the message.number | boolean
deliveredToCountDelivery count of the message.number
showMessageOverlayOpens the message action overlay (called on long press).(showMessageReactions?: boolean) => void
showReactionsOverlayOpens the reactions overlay.(selectedReaction?: string) => void
showMessageStatusWhen false, message status (read receipt, pending indicator) isn't rendered. Defaults to true for messages sent by the current user.boolean
goToMessageScrolls to a specific message ID.(messageId: string) => void | undefined
handleReactionHandles adding/removing a reaction.(reactionType: string) => Promise<void> | undefined
myMessageThemeTheme applied to the current user's messages. Memoize this object or pass a stable reference.object
preventPressPrevent message being pressed (for example in image viewer contexts).boolean
showAvatarWhether avatar should be shown next to the message.boolean
onThreadSelectThread selection callback.function
setQuotedMessageSet quoted-reply state for a message.(message) => void
threadListTrue if the current message is part of a thread.boolean
videosArray of video attachments.array
channelCurrent channel instance.channel
membersMembers of current channel. This value is received from backend when you query a channel, either using client.queryChannels() or channel.watch() API call. Note: client.queryChannels() or channel.watch() returns only up to 100 members of channel. If you expect total number of members to be > 100, use client.queryMembers() API endpoint separately.object

Examples

actionsEnabled

message.type === "regular" && message.status === "received";

images

const images = message.attachments.filter((a) => a.type === "image");

reactions

[
  {
    own: true,
    type: "love",
  },
  {
    own: false,
    type: "haha",
  },
];

videos

const videos = message.attachments.filter(
  (a) => a.type === "video" && !a.og_scrape_url,
);