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>"}
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>"
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>"}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.
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 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. At the moment thread
information contains only the number of non-deleted messages
in thread.