Skip to main content
CometChatTextFormatter is an abstract class for formatting text in the message composer and message bubbles. Extend it to build custom formatters — hashtags, keywords, or any regex-based pattern.

The Formatter Interface

The CometChatTextFormatter class provides the foundation for all text formatters in React Native:

Steps

1. Import the base class

2. Extend it

3. Match the pattern in formatRawText

formatRawText() receives the raw message text as a string, before any of the UI Kit’s own parsing, and returns a string. Rewrite your pattern into markup the UI Kit already draws — here, color and bold:
Do not put the pattern matching in getFormattedText(). That method runs after the built-in Markdown formatter, which hands it JSX rather than a string — so the usual if (typeof inputText !== "string") return inputText; guard returns early and your formatter silently does nothing on any message containing _, **, - , [ or a backtick. It works only on messages with no Markdown at all, which is why the failure is easy to miss in testing.

Example

A hashtag formatter used with CometChatMessageList and CometChatCompactMessageComposer.
Sending hello #world **bold** _italic_ now renders #world green and bold, with the Markdown around it still formatted.
A formatter only applies where you register it. CometChatMessageList, CometChatConversations, CometChatSearch, CometChatPinnedMessages, CometChatSavedMessages and CometChatCompactMessageComposer each take textFormatters. Media captions, the quoted reply inside a bubble, the reply and edit previews, and the message information screen inherit it from the component that renders them.

Methods Reference


Advanced: Suggestion List Integration

For formatters that need to show suggestions (like mentions), implement the search method:

Next Steps

Custom Text Formatter

Build an app-defined color marker end to end.

Mentions Formatter

Add @mentions with styled tokens.

URL Formatter

Auto-detect and style URLs as clickable links.

All Guides

Browse all feature and formatter guides.

Sample App

Full working sample application on GitHub.