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.
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";exportconstExample=()=>{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-screenwidth:"300px"// Recommended so that threads don't stretch horizontally based on their content}}/>);};
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.
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.
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.
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.
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).
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.
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.
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.
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.
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
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
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
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; }.
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; }
Callback invoked when a user focuses the composer.
The callback is passed one argument which is an object of type {threadId: string; thread: ThreadSummary}
Callback invoked when the composer loses focus.
The callback is passed one argument which is an object of type {threadId: string; thread: ThreadSummary}
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}