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>
);
};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
autoscrollToBottomonly for user-triggered layout changes in virtualized lists. - Keep custom rendering logic focused on UI; let the built-in handlers perform channel actions.
- Treat edit flows as part of the message composer, not as local message state.
Basic Usage
Pull values from MessageContext with the useMessageContext hook:
Values
| Value | Description | Type |
|---|---|---|
actionsEnabled | Whether message actions are enabled for the message. | boolean |
autoscrollToBottom | Keeps a virtualized list pinned to the bottom when message height changes. | () => void |
closeReactionSelectorOnClick | Whether ReactionSelector should close after a choice is made. | boolean |
deliveredTo | Users who have confirmed device delivery. | UserResponse[] |
endOfGroup | Whether the message is the last item in its visual group. | boolean |
firstOfGroup | Whether the message is the first item in its visual group. | boolean |
formatDate | Custom date formatter used by message timestamp components. | (date: Date) => string |
getMessageActions | Returns the allowed actions for the current message. | () => MessageActionsArray<string> |
groupedByUser | Whether the surrounding virtualized list groups messages by user. | boolean |
groupStyles | Grouping styles applied to the message. | GroupStyle[] |
handleAction | Executes a message action. | (dataOrName?: string | FormData, value?: string, event?: React.BaseSyntheticEvent) => Promise<void> |
handleDelete | Deletes the current message. | (options?: DeleteMessageOptions) => Promise<void> | void |
handleFetchReactions | Loads reactions for the current message. | (reactionType?: ReactionType, sort?: ReactionSort) => Promise<ReactionResponse[]> |
handleFlag | Flags the message. | ReactEventHandler |
handleMarkUnread | Marks the message and following messages unread. | ReactEventHandler |
handleMute | Mutes the message sender. | ReactEventHandler |
handleOpenThread | Opens the thread for the current message. | ReactEventHandler |
handlePin | Pins or unpins the message. | ReactEventHandler |
handleReaction | Adds or removes a reaction. | (reactionType: string, event: React.BaseSyntheticEvent) => Promise<void> |
handleRetry | Retries sending a failed message. | ChannelActionContextValue["retrySendMessage"] |
highlighted | Whether the message should be highlighted on load. | boolean |
initialMessage | Whether the message is the thread parent in a thread list. | boolean |
isMessageAIGenerated | Optional AI-message detection function from Chat. | (message: LocalMessage) => boolean |
isMyMessage | Returns whether the message belongs to the connected user. | () => boolean |
lastOwnMessage | The latest own message in the currently rendered set. | LocalMessage |
lastReceivedId | Latest message ID in the current channel. | string | null |
message | The current message object. | LocalMessage |
messageIsUnread | Whether the message is currently unread for the connected user. | boolean |
messageListRect | DOM rect of the surrounding message list. | DOMRect |
mutes | Muted users from the current channel state. | Mute[] |
onMentionsClickMessage | Mention click handler used by message text. | ReactEventHandler |
onMentionsHoverMessage | Mention hover handler used by message text. | ReactEventHandler |
onUserClick | Handler for clicking the message sender. | ReactEventHandler |
onUserHover | Handler for hovering the message sender. | ReactEventHandler |
pinPermissions | Legacy pin-permission config. | PinPermissions |
reactionDetailsSort | Sort options for loading reaction details. | ReactionSort |
readBy | Users who have read the message. | UserResponse[] |
renderText | Custom text renderer used by MessageText and StreamedMessageText. | MessageContextValue["renderText"] |
returnAllReadData | Whether read data should be kept for every own message. | boolean |
setTranslationView | Updates the translation mode for this message. | (view: "original" | "translated") => void |
showAvatar | Avatar display mode used by the current message UI. | boolean | "incoming" | "outgoing" |
sortReactionDetails | Legacy comparator for reaction details. | ReactionDetailsComparator |
sortReactions | Comparator for grouped reactions. | ReactionsComparator |
threadList | Whether the message is being rendered in a thread list. | boolean |
translationView | Current translation mode for the message text. | "original" | "translated" |
unsafeHTML | Whether the current message should render HTML instead of markdown. | boolean |