Skip to main content
FieldValue
Package@cometchat/chat-uikit-react
Key classCometChatMentionsFormatter (extends CometChatTextFormatter)
Required setupCometChatUIKit.init(UIKitSettings) then CometChatUIKit.login("UID")
PurposeFormat @mentions with styled tokens, suggestion list, and click handling for users and group members
Sample appGitHub
RelatedCustom Text Formatter | All Guides
CometChatMentionsFormatter extends CometChatTextFormatter to format @mentions in text messages. It styles mention tokens, generates suggestion lists as users type, and handles click events on rendered mentions.
CapabilityDescription
Mention formattingAuto-formats <@uid:...> placeholders into styled tokens
Custom stylesColors, fonts, and backgrounds for mention text
User and group mentionsWorks with both individual users and group members
Suggestion listGenerates mention candidates from user input
Click handlingListener interface for tap/click on rendered mentions

Usage

1. Initialize the formatter

import { CometChatMentionsFormatter } from "path-to-your-file";

const mentionsFormatter = new CometChatMentions();
mentionsFormatter.setCometChatUserGroupMembers(userList);

2. Format a message

Provide the raw message string containing mention placeholders, then apply the formatter:
const unformattedMessage = "<@uid:aliceuid> just shared a photo!";
const formattedMessage = mentionsFormatter.getFormattedText(unformattedMessage);
// Render formattedMessage in your message component
The output contains HTML with styled mentions ready for rendering.

3. Pass to components

Use the textFormatters prop on CometChatMessageList, CometChatMessageComposer, or CometChatConversations.

Next Steps