Build rich integrations with detailed data about one thread and all of its messages
import { thread } from '@cord-sdk/react';
const { messages, thread, loading, hasMore, fetchMore } = thread.useThread('my-awesome-thread-id');
return (
<div>
{thread ?
<p> {thread.unread} / {thread.total} unread messages </p>
: null}
{messages.map((messageSummary) => (
<div key={messageSummary.id}>
Message ID {messageSummary.id} was created at {messageSummary.createdTimestamp}!
</div>
))}
{loading ? (
<div>Loading...</div>
) : hasMore ? (
<div onClick={() => fetchMore(10)}>Fetch 10 more</div>
) : null}
</div>
);
The API provides an object which has the following fields:
fetchMore
will cause further messages to be appended to the array.This is an array of objects, each of which has the following fields:
Show property details
This property can be one of the following:
This is an object with the following fields:
Show property details
true
, Cord is in the process of fetching additional data from its backend. Once the fetch is complete, the additional items will be appended to the result list, and loading
will become false
.fetchMore
will start a fetch and cause loading
to become true
.loading
will become true
while the data is fetched. Once the fetch is complete, the additional items will be appended to the result list, and loading
will return to false
.true
, then the list of results is incomplete, and you need to call fetchMore
to continue paginating through them. Once this becomes false
, all results are available, and calls to fetchMore
won't do anything.loading
will be true
, thread
will be undefined
, and messages
an empty array 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 full data. The component will automatically re-render if any of the data changes, i.e., this data is always "live".This is an object with the following fields:
Show property details
Not finding the answer you need? Ask our Developer Community