Skip to content

Commit

Permalink
ThreadList adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Sep 16, 2024
1 parent e08abbf commit 8888435
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions docusaurus/docs/React/components/core-components/thread-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,42 @@ id: thread-list
title: ThreadList
---

`ThreadList` is a component which renders individual thread instances ([`Thread`](https://github.com/GetStream/stream-chat-js/blob/master/src/thread.ts)) stored within [`ThreadManager`](https://github.com/GetStream/stream-chat-js/blob/master/src/thread_manager.ts). It handles pagination triggers and virtualization through the help of the [Virtuoso](https://virtuoso.dev) virtualized list component. The rest of the business logic lives within ThreadManager and Thread classes. ThreadManager instance gets activated whenever ThreadList renders - activation is necessary as it tells the SDK that user "sees" this list and can update state accordingly whenever appropriate events arrive.

If used in default form and rendered within [`ThreadView` component](../utility-components/chat-view.mdx) it also allows to set active thread and handles [`Thread`](https://github.com/GetStream/stream-chat-js/blob/master/src/thread.ts) activation (similar to [`ThreadManager`](https://github.com/GetStream/stream-chat-js/blob/master/src/thread_manager.ts) activation).
`ThreadList` is a component that displays a list of threads where the current user is a participant (this user either started a thread, replied to a thread or was tagged in a thread). It handles pagination and virtualization through the help of the [virtualized list component](https://virtuoso.dev). The rest of the business logic (data manipulation) lives within [`ThreadManager`](https://github.com/GetStream/stream-chat-js/blob/master/src/thread.ts) and [`Thread`](https://github.com/GetStream/stream-chat-js/blob/master/src/thread_manager.ts) classes. Data represented through `ThreadList` are accessible from client instance (`client.threads.state`).

## Basic Usage

The `ThreadList` component requires to be rendered within `Chat` component but apart from that does not require any other context to work.

```tsx
import { Chat, ThreadList } from 'stream-chat-react';

<Chat client={client}>
{/*...*/}
<ThreadList />
</Chat>
</Chat>;
```

For extended "out of the box" functionality `ThreadList` can be rendered within [`ChatView.Threads`](../utility-components/chat-view.mdx) component where individual items within the list become "selectable" through the `ThreadViewContext`. Selected/active thread can be then accessed from this context as well. See [`ChatView` documentation](../utility-components/chat-view.mdx) for extended functionality.

```tsx
import { Chat, ChatView, ThreadList, useThreadsViewContext } from 'stream-chat-react';

const SelectedThread = () => {
const { activeThread } = useThreadsViewContext();

return null;
};

<Chat client={client}>
<ChatView>
<ChatView.Selector />
{/*...*/}
<ChatView.Threads>
<ThreadList />
<SelectedThread />
</ChatView.Threads>
</ChatView>
</Chat>;
```

## Props
Expand Down

0 comments on commit 8888435

Please sign in to comment.