Display, add and remove reactions on existing messages
By itself, the Reactions component does not show the message it belongs to. Click here to see it in context paired with a Message component!
The Reactions
component renders both a container that displays reactions and a button you can use to add and remove reactions belonging to a particular message. This component works similarly to reactions you might have seen in Slack or WhatsApp. When the user clicks an existing reaction, they will react to the message with the same emoji and the count will increase. If they select the same reaction a second time, their reaction will be removed and the count will decrease.
You can use this alongside other Cord components to build any message layout that you might need. For example, you can use our Thread API to get the thread and messages IDs you need to hook this up to the exact message you want.
import { Reactions, thread } from "@cord-sdk/react";
// Adding a Reactions component to the first message of a thread.
export const Example = () => {
const threadId = useMemo(() => 'thread-' + Date.now(), []);
const threadSummary = thread.useThreadSummary(threadId);
return (
<>
<p>Add an initial message which you can react to:</p>
{threadId && <Thread threadId={threadId} />}
{threadId && threadSummary?.firstMessage?.id && (
<Reactions
threadId={threadId}
messageId={threadSummary.firstMessage.id}
/>
)}
</>
);
};
messageId
.threadId
.true
, a button to add reactions is appended to the parent container.true
.true
, a container displaying reactions is prepended to the parent container.true
.If you want to customize this component, you can target the classes below in your app's CSS. These are guaranteed to be stable.
.cord-reactions-container
.cord-reaction-list
.cord-add-reaction
.cord-pill
.cord-from-viewer
.cord-emoji
.cord-count