Skip to main content
Quick Reference - Add and remove reactions:
// Add a reaction
await CometChat.addReaction("MESSAGE_ID", "😊");

// Remove a reaction
await CometChat.removeReaction("MESSAGE_ID", "😊");
Available via: SDK | REST API | UI Kits
Enhance user engagement in your chat application with message reactions. Users can express their emotions using reactions to messages. This feature allows users to add or remove reactions, and to fetch all reactions on a message. You can also listen to reaction events in real-time. Let’s see how to work with reactions in CometChat’s SDK.

Add a Reaction

Users can add a reaction to a message by calling addReaction with the message ID and the reaction emoji.
let messageId = "1";
let emoji = "😊";

CometChat.addReaction(messageId, emoji)
.then((res) => {
  console.log('response', res);
}).catch(err => {
  console.log('err', err);
})
You can react on text message, media message and custom message

Remove a Reaction

Removing a reaction from a message can be done using the removeReaction method.
let messageId = "1";
let emoji = "😊";

CometChat.removeReaction(messageId, emoji)
.then((res) => {
  console.log('response', res);
}).catch(err => {
  console.log('err', err);
})

Fetch Reactions for a Message

To get all reactions for a specific message, first create a ReactionRequest using ReactionRequestBuilder. You can specify the number of reactions to fetch with setLimit with max limit 100. For this, you will require the ID of the message. This ID needs to be passed to the setMessageId() method of the builder class. The setReaction() will allow you to fetch details for specific reaction or emoji.
SettingDescription
setMessageId(value)Specifies the unique identifier of the message for which you want to fetch reactions. This parameter is mandatory as it tells the SDK which message’s reactions are being requested.
setReaction(value)Filters the reactions fetched by the specified reaction type (e.g., ”😊”, ”😂”, ”👍”). When set, this method will cause the ReactionRequest to only retrieve details of the provided reaction for the given message.

Fetch Next

The fetchNext() method fetches the next set of reactions for the message.
let limit = 10;
let messageId = 1;

let reactionRequest = new CometChat.ReactionRequestBuilder()
.setMessageId(messageId)
.setLimit(limit)
.build();

reactionRequest.fetchNext().then(
    messages => {
      console.log("list fetched:", messages);
    },
    error => {a
      console.log('list fetching failed with error:', error);
    },
  );

Fetch Previous

The fetchPrevious() method fetches the previous set of reactions for the message.
let limit = 10;
let messageId = 1;

let reactionRequest = new CometChat.ReactionRequestBuilder()
.setMessageId(messageId)
.setLimit(limit)
.build();

reactionRequest.fetchPrevious().then(
    messages => {
      console.log("list fetched:", messages);
    },
    error => {a
      console.log('list fetching failed with error:', error);
    },
  );

Real-time Reaction Events

Keep the chat interactive with real-time updates for reactions. Register a listener for these events and make your UI responsive.
let listenerID = "UNIQUE_LISTENER_ID";

CometChat.addMessageListener(listenerID, {
    onMessageReactionAdded:(message) => {
      console.log("Reaction added", message);
    },
    onMessageReactionRemoved:(message) => {
      console.log("Reaction removed", message);
    }
  })

Removing a Reaction Listener

To stop listening for reaction events, remove the listener as follows:
let listenerID = "UNIQUE_LISTENER_ID";

CometChat.removeMessageListener(listenerID);
Always remove your reaction listeners when they are no longer needed — for example, when a component unmounts or a screen is navigated away from. Failing to do so can cause memory leaks and unexpected behavior from stale listeners. Use CometChat.removeMessageListener("LISTENER_ID") in your cleanup logic (e.g., useEffect return function or componentWillUnmount).

Get Reactions List

To retrieve the list of reactions reacted on particular message, you can use the message.getReactions() method. This method will return an array containing the reactions, or an empty array if no one reacted on the message.
message.getReactions()

Check if Logged-in User has Reacted on Message

To check if the logged-in user has reacted on a particular message or not, You can use the getReactedByMe() method on any ReactionCount object instance. This method will return a boolean value, true if the logged-in user has reacted on that message, otherwise false.
let reactions = message.getReactions();
reactions.forEach((reaction) => {
reaction.getReactedByMe(); //Return true is logged-in user reacted on that message, otherwise false
})

Update Message With Reaction Info

When a user adds or removes a reaction, you will receive a real-time event. Once you receive the real time event you would want to update the message with the latest reaction information. To do so you can use the updateMessageWithReactionInfo() method. The updateMessageWithReactionInfo() method provides a seamless way to update the reactions on a message instance (BaseMessage) in real-time. This method ensures that when a reaction is added or removed from a message, the BaseMessage object’s getReactions() property reflects this change immediately. When you receive a real-time reaction event (MessageReaction), call the updateMessageWithReactionInfo() method, passing the BaseMessage instance (message), event data (MessageReaction) and reaction event action type (CometChat.REACTION_ACTION.REACTION_ADDED or CometChat.REACTION_ACTION.REACTION_REMOVED) that corresponds to the message being reacted to.
// The message to which the reaction is related
let message = ...;

// The reaction event data received in real-time
let messageReaction = ...;

// The recieved reaction event real-time action type. Can be CometChatConstants.REACTION_ADDED or CometChatConstants.REACTION_REMOVED
let action = CometChat.REACTION_ACTION.REACTION_ADDED;

let modifiedBaseMessage = CometChat.CometChatHelper.updateMessageWithReactionInfo(
baseMessage, 
messageReaction, 
action
);   

Best Practices

Always use unique, descriptive listener IDs (e.g., "ChatScreen_ReactionListener") to avoid conflicts with other listeners in your app. This makes it easier to manage and remove specific listeners when needed.
Remove reaction listeners in your component’s cleanup phase (useEffect return function or componentWillUnmount). Orphaned listeners can lead to memory leaks and unexpected UI updates on unmounted components.
When you receive a real-time reaction event, always call updateMessageWithReactionInfo() to keep your local message state in sync. This avoids stale reaction counts and ensures the UI reflects the latest state.
Wrap addReaction and removeReaction calls in proper error handling. Network issues or invalid message IDs can cause failures — show appropriate feedback to the user rather than silently failing.
When fetching reactions for messages with many reactions, use fetchNext() with a reasonable setLimit() value. Avoid fetching all reactions at once to keep performance smooth, especially on lower-end devices.

Troubleshooting

Verify that the messageId is valid and the user is logged in. Check the error callback for details — common causes include invalid message IDs, network connectivity issues, or the user not being a participant in the conversation.
Ensure you have registered the message listener with CometChat.addMessageListener() before the reaction event occurs. Also confirm that the listener ID is unique and hasn’t been accidentally removed or overwritten by another listener registration.
After receiving a real-time reaction event, you must call CometChat.CometChatHelper.updateMessageWithReactionInfo() to update the message object. Simply receiving the event does not automatically update the BaseMessage instance — you need to explicitly apply the update and re-render.
Make sure you are calling getReactedByMe() on the ReactionCount objects returned by message.getReactions(), not on the raw reaction event data. Also verify that the logged-in user is the same user who added the reaction.
Confirm that the messageId passed to ReactionRequestBuilder.setMessageId() is correct and that the message actually has reactions. If using setReaction() to filter by a specific emoji, ensure the emoji string matches exactly (including any variation selectors).

Next Steps

Explore related features to build a richer messaging experience: