Build activity indicators and badges with information about a thread and its messages
This method allows you to observe summary information about a thread, including live updates.
import { thread } from '@cord-sdk/react';
const summary = thread.useThreadSummary(threadId, options);
import { thread } from '@cord-sdk/react';
const summary = thread.useThreadSummary('my-awesome-thread-id');
return (
<div>
{!summary && "Loading..."}
{summary && (
<p>Total messages: {summary.total}</p>
<p>Unread messages: {summary.unread}</p>
)}
</div>
);
The API provides an object which has the following fields:
Contains information about users that are subscribed to this thread. An array of objects, one for each subscriber. Each object contains the following fields:
null
if this participant has never viewed this
thread.The name of the thread. This typically defaults to the title of the page where the thread was created, but it can be set manually by the Thread component. You might use this in places where a short name or header is useful to distinguish the thread.
Never null, but can be empty.
Contains information about the first (i.e., oldest) message in the thread. null
if the thread is empty. Otherwise, contains the following fields:
null
if the message is not deleted.The hook will initially return undefined
while the data loads from our API. Once it has loaded, your component will re-render and the hook will return an object containing the fields described under "Available Data" above. The component will automatically re-render if any of the data changes, i.e., this data is always "live".
The thread ID to fetch summary information for. If a thread with this ID does not exist, it will be created.
Miscellaneous options. See below.
Loading information for a thread ID which does not exist will create that thread. If that happens, this will be the name of the new thread.
If unset, this will default to the current page's title.
Loading information for a thread ID which does not exist will create that thread. If that happens, this will be the location of the new thread.
If unset, this will default to the location provided to theuseCordLocation
hook if that was used. Otherwise, will default to the current page's URL.`