This is beta documentation for Stream Chat React SDK v14. For the latest stable version, see the latest version (v13) .

MessageContext

MessageContext is created by Message and consumed by message UI components such as MessageSimple, MessageStatus, and your own custom message components.

Best Practices

  • Use useMessageContext() inside message UI instead of passing message data through props.
  • Prefer getMessageActions() over hard-coding action availability.
  • Use autoscrollToBottom only for user-triggered layout changes in virtualized lists.
  • Keep custom rendering logic focused on UI; let the built-in handlers perform channel actions.
  • Treat handleDelete() as async in custom UIs and catch failures if your app needs extra recovery.
  • Treat edit flows as part of the message composer, not as local message state.
  • Treat pinning as capability-driven. MessageContext no longer carries a pinPermissions override.

Basic Usage

Pull values from MessageContext with the useMessageContext hook:

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

const CustomMessage = () => {
  const { getMessageActions, isMyMessage, message, threadList } =
    useMessageContext();

  return (
    <div>
      <div>{message.text}</div>
      <div>{isMyMessage() ? "mine" : "theirs"}</div>
      <div>{threadList ? "thread" : "channel"}</div>
      <div>{getMessageActions().join(", ")}</div>
    </div>
  );
};

Values

ValueDescriptionType
actionsEnabledWhether message actions are enabled for the message.boolean
autoscrollToBottomKeeps a virtualized list pinned to the bottom when message height changes.() => void
closeReactionSelectorOnClickWhether ReactionSelector should close after a choice is made.boolean
deliveredToUsers who have confirmed device delivery.UserResponse[]
endOfGroupWhether the message is the last item in its visual group.boolean
firstOfGroupWhether the message is the first item in its visual group.boolean
formatDateCustom date formatter used by message timestamp components.(date: Date) => string
getMessageActionsReturns the allowed actions for the current message.() => MessageActionsArray<string>
groupedByUserWhether the surrounding virtualized list groups messages by user.boolean
groupStylesGrouping styles applied to the message.GroupStyle[]
handleActionExecutes a message action.(dataOrName?: string | FormData, value?: string, event?: React.BaseSyntheticEvent) => Promise<void>
handleDeleteDeletes the current message. For unsent or network-failed messages, it removes the message locally instead. Delete failures are rethrown after the SDK notifies the user.(options?: DeleteMessageOptions) => Promise<void> | void
handleFetchReactionsLoads reactions for the current message.(reactionType?: ReactionType, sort?: ReactionSort) => Promise<ReactionResponse[]>
handleFlagFlags the message.ReactEventHandler
handleMarkUnreadMarks the message and following messages unread.ReactEventHandler
handleMuteMutes the message sender.ReactEventHandler
handleOpenThreadOpens the thread for the current message.ReactEventHandler
handlePinPins or unpins the message.ReactEventHandler
handleReactionAdds or removes a reaction.(reactionType: string, event: React.BaseSyntheticEvent) => Promise<void>
handleRetryRetries sending a failed message.ChannelActionContextValue["retrySendMessage"]
highlightedWhether the message should be highlighted on load.boolean
initialMessageWhether the message is the thread parent in a thread list.boolean
isMessageAIGeneratedOptional AI-message detection function from Chat.(message: LocalMessage) => boolean
isMyMessageReturns whether the message belongs to the connected user.() => boolean
lastOwnMessageThe latest own message in the currently rendered set.LocalMessage
lastReceivedIdLatest message ID in the current channel.string | null
messageThe current message object.LocalMessage
messageIsUnreadWhether the message is currently unread for the connected user.boolean
messageListRectDOM rect of the surrounding message list.DOMRect
mutesMuted users from the current channel state.Mute[]
onMentionsClickMessageMention click handler used by message text.ReactEventHandler
onMentionsHoverMessageMention hover handler used by message text.ReactEventHandler
onUserClickHandler for clicking the message sender.ReactEventHandler
onUserHoverHandler for hovering the message sender.ReactEventHandler
reactionDetailsSortSort options for loading reaction details.ReactionSort
readByUsers who have read the message.UserResponse[]
renderTextCustom text renderer used by MessageText and StreamedMessageText.MessageContextValue["renderText"]
returnAllReadDataWhether read data should be kept for every own message.boolean
setTranslationViewUpdates the translation mode for this message.(view: "original" | "translated") => void
showAvatarAvatar display mode used by the current message UI.boolean | "incoming" | "outgoing"
sortReactionsComparator for grouped reactions.ReactionsComparator
threadListWhether the message is being rendered in a thread list.boolean
translationViewCurrent translation mode for the message text."original" | "translated"
unsafeHTMLWhether the current message should render HTML instead of markdown.boolean