Display conversations anywhere in your product


When to use #

The Thread component renders a single conversation thread, or a message composer to create a new thread. Threads contain everything your users need to have a conversation.

This component pairs well with:


How to use #

React:
import { Thread } from "@cord-sdk/react";

export const Example = () => {
  return (
    <Thread
      threadId={"<any string that is unique across your entire application>"}
      groupId="my-group"
      location={{ "page": "index" }}
      metadata={{ "foo": "bar" }}
      onThreadInfoChange={({ messageCount }) => {
        console.log("thread has", messageCount, "messages");
      }}
      onClose={() => {
        console.log("User clicked close button");
      }}
      onResolved={() => {
        console.log("User resolved the thread");
      }}
      style={{
        maxHeight: "400px", // Recommended so that long threads scroll instead of disappearing off-screen
        width: "300px" // Recommended so that threads don't stretch horizontally based on their content
      }}
    />
  );
};
Vanilla JavaScript:
<cord-thread
  thread-id="<id of thread>"
  group-id="my-group"
  location='{ "page": "index" }'
  metadata='{ "foo": "bar" }'
  // Setting a max-height is recommended so that long threads scroll instead of disappearing off-screen
  // Setting a width is recommended so that threads don't stretch horizontally based on their content
  style="max-height: 400px; width: 300px;"
></cord-thread>
import { Thread } from "@cord-sdk/react";

export const Example = () => {
  return (
    <Thread
      threadId={"<any string that is unique across your entire application>"}
      groupId="my-group"
      location={{ "page": "index" }}
      metadata={{ "foo": "bar" }}
      onThreadInfoChange={({ messageCount }) => {
        console.log("thread has", messageCount, "messages");
      }}
      onClose={() => {
        console.log("User clicked close button");
      }}
      onResolved={() => {
        console.log("User resolved the thread");
      }}
      style={{
        maxHeight: "400px", // Recommended so that long threads scroll instead of disappearing off-screen
        width: "300px" // Recommended so that threads don't stretch horizontally based on their content
      }}
    />
  );
};
Copy

Properties #


threadId #

required
string
An arbitrary string that uniquely identifies a thread. When your page loads, the Cord client SDK will load the thread associated with this thread identifier and display the messages. If the thread doesn't exist yet, Cord's backend will create it on the fly.
Warning! An important restriction of working with thread identifiers is that they must be unique across your entire application. You can't use the same thread identifier in two separate groups. This is an intentional limitation imposed by Cord.

groupId #

optional
string
The group ID which this thread should belong to. This controls which users will be able to see the Thread.
Required when creating a new thread. If loading an existing thread ID, specifying a group ID which does not match the group the thread belongs to will result in an error.

location #

optional
string
The location concept for the thread component.
If unset, this field will default to the current URL for the page.

threadName #

optional
string
Sets the name of the thread. The thread name is used in a small number of places where a short name or header is useful to distinguish the thread; the default value is nearly always fine. A newly-created thread will have its title set to this value, and an existing thread will have its title updated to this value.
The default setting is the current page's title.

metadata #

optional
object
A JSON object that can be used to store metadata about a thread. Keys are strings, and values can be strings, numbers or booleans.
A newly-created thread will have its metadata set to this value, and an existing thread will have its metadata updated to this value. If the metadata property is unset, the thread's existing metadata is preserved.

collapsed #

optional
boolean
If true, the thread will render in a smaller, collapsed state. The header and message composer will be hidden, and only the first message in the thread will be visible (with a "N replies" link underneath to expand further replies in the thread).
The default value is false.

autofocus #

optional
boolean
If true, the thread's message composer input field will render with the autofocus HTML attribute set.
The default value is false.

showHeader #

optional
boolean
If true, a header will be shown at the top of the thread. The header contains some extra dropdowns and actions relating to the thread, such as "Share via email" and "Unsubscribe". If collapsed is true, this attribute is ignored (the header is always hidden in collapsed threads). In threads with no messages the extra dropdown will not be rendered, only a close button.
The default value is false.

composerExpanded #

optional
boolean
If true, the composer of the thread will always appear expanded. This means that it will always show the button list (such as the mention button and emoji button) right below the editor. If it is set to false, the composer will start from a single-line state, but will expand when a user clicks in the editor or starts typing. It will return to a single-line state when it loses focus and there is no input in the editor.
This value defaults to false.

composerDisabled #

optional
boolean
If true, the composer of the thread will render in a disabled state, preventing writing or sending a message. This can be used, for example, to visually suggest the user can not or should not send a message to the thread. However, it is not a permission control, since it does not prevent the user from sending to the thread directly (such as via the JS API). Only Cord's groups should be used for permissions.
The default value is false.

showPlaceholder #

optional
boolean
If false, when the thread has no messages, it will show only the composer. If set to true, it will instead show a placeholder, containing a set of users from the group and a description to prompt sending a message.
The default value is true.

onLoading #

optional
function
Callback invoked when the component begins loading. Use onRender to determine when loading is complete.

onRender #

optional
function
Callback invoked when the component has finished rendering. Use onLoading to determine when a component begins loading.

onThreadInfoChange #

optional
function
Callback invoked when the thread is first loaded and when the thread information changes. The callback is passed one argument, threadInfo which is an object of type {messageCount: number; thread: ThreadSummary} containing the number of non-deleted messages in the thread and the thread's summary

onClose #

optional
function
Callback invoked when a user clicks on the close button in the thread header. The callback is passed one argument, threadInfo which is an object of type {thread: ThreadSummary} containing the thread's summary

onResolved #

optional
function
Callback invoked when a user resolves the thread. The callback is passed one argument, threadInfo which is an object of type {thread: ThreadSummary} containing the thread's summary

onMessageEditStart #

optional
function
Callback invoked when a user starts editing a message in the Thread. The callback is passed an object of type { threadId: string; messageId: string; thread: ThreadSummary; message: ClientMessageData; }.

onMessageEditEnd #

optional
function
Callback invoked when a user completes editing a message in the Thread. The callback is passed an object of type { threadId: string; messageId: string; thread: ThreadSummary; message: ClientMessageData; }

onFocusComposer #

optional
function
Callback invoked when a user focuses the composer. The callback is passed one argument which is an object of type {threadId: string; thread: ThreadSummary}

onBlurComposer #

optional
function
Callback invoked when the composer loses focus. The callback is passed one argument which is an object of type {threadId: string; thread: ThreadSummary}

onSend #

optional
function
Callback invoked when a new message is sent from the Thread's composer. The callback is passed one argument which is an object of type {threadId: string; messageId: string; thread: ThreadSummary}



Not finding the answer you need? Ask our Developer Community

Ask Cordy