Put messages wherever you want. Don't worry, we'll handle reactions, as well as deleted, editing and unread states for you!


This component is in development; interface and features are subject to change prior to final release.

Visit the Replacements API step by step guide.

When to use #

The <Message /> component renders a fully baked message. It gives your users an intuitive commenting UI that matches the experience of using a well-crafted chat in tools like Slack or Figma. You don't have to worry about how users add reactions, how they edit a message, how they delete one, or whether it is seen or unseen by the current user. We've got you covered! It will even handle timestamps that update live on the page while you're chatting.

This component starts you off with a 10/10 of message experience that you can customize as you need.

Do you want to build a chat? Maybe Slack-like threads? Or even a thread preview? Pair this component with our Thread API to access the data you need and create the experiences you want! Specifically, check out the get threads API and the get thread API to fetch relevant thread IDs and message IDs for a particular location or thread respectively.


How to use #

React:
import { betaV2, thread } from "@cord-sdk/react";
  
  function ExampleMessage({messageID}) {
    const message = thread.useMessage(messageID);

    return <betaV2.Message
      message={message}
    />;
  }
import { betaV2, thread } from "@cord-sdk/react";
  
  function ExampleMessage({messageID}) {
    const message = thread.useMessage(messageID);

    return <betaV2.Message
      message={message}
    />;
  }
Copy

Alternatively, you can use Message.ByID to render a message given its ID. We'll do the data fetching for you.

React:
import { betaV2, thread } from "@cord-sdk/react";
  
  function ExampleByIDMessage({messageID}) {
    return <betaV2.Message.ByID
      messageId={messageID}
    />;
  }
import { betaV2, thread } from "@cord-sdk/react";
  
  function ExampleByIDMessage({messageID}) {
    return <betaV2.Message.ByID
      messageId={messageID}
    />;
  }
Copy

View Source Code


Properties #

<Message /> #


message #

required
ClientMessageData
Contains the data of the message to be displayed.

This is an object with the following fields:

Show property details



showThreadOptions #

optional
boolean
If set to true, the thread options will appear within the message options menu. Defaults to false.


style #

optional
CSSProperties
Passes the style of the component. It will be applied to the root element.


className #

optional
string
Any classes to be added to the component. It will be applied to the root element.


replace #

optional
ReplaceConfig
Object that contains the components that will be replaced in the message. Find more information about it here.

<Message.ByID /> #


messageID #

required
string
The ID of the message to be displayed.


style #

optional
CSSProperties
Passes the style of the component. It will be applied to the root element.


className #

optional
string
Any classes to be added to the component. It will be applied to the root element.


replace #

optional
ReplaceConfig
Object that contains the components that will be replaced in the message. Find more information about it here.

Customization with Replacements #

If you want to customize your component, you can customize the CSS (see below), but you can also switch parts of the component for your own ones with out Replacements API.

These are the components you can replace in the message. Some are better understood in context. We suggest inspecting the component with your browser's developer tools to find elements with a data-cord-replace attribute.

ComponentDescription
MessageLayout
Layout for the message.
ReactionPickButton
Button to add reactions.
Reactions
Container for reaction emojis.
Avatar
Container for user avatars.
Button
Generic button component.
Timestamp
Display for message timestamp. Shown next to the name by default.
OptionsMenu
Appears when hovering over a message, the three dots button.

CSS customization #

If you want to customize this component, you can target the classes below in your app's CSS. These are guaranteed to be stable.

There are more classes that are best understood in context. We suggest inspecting the component with your browser's developer tools to view everything. You can target any classes starting with cord-.

Class nameDescription
.cord-message
Applied to the container div. You can use grid-template-areas to modify the layout of the message.
.cord-author-name
Applied to the div containing the name of the author of the message.
.cord-message-content
Applied to the div containing the text of the message and any attachments.
.cord-options-menu-trigger
Applied to the div which appears on hover on the top right of the message.
.cord-deleted-icon
Applied to the div that contains the icon which appears when users delete a message.
.cord-deleted-message-text
Applied to the div that contains the label that appears when users delete a message.
.cord-undo-delete-button
Applied to the "undo" button that appears when users delete a message.


Not finding the answer you need? Ask our Developer Community

Ask Cordy