# ThreadContext

`ThreadContext` is provided by [`Channel`](https://getstream.io/chat/docs/sdk/react-native/core-components/channel/). If you are not familiar with the React Context API, see the [React docs](https://reactjs.org/docs/context.html).

## Best Practices

- Use `useThreadContext` for consistent access and typings.
- Manage thread navigation via `openThread`/`closeThread` rather than manual state.
- Use `threadHasMore` and `threadLoadingMore` to control pagination.
- Keep thread UI logic separate from channel message lists.
- Avoid heavy computations in thread context consumers.

## Basic Usage

Consume `ThreadContext` in any child of `Channel`:

```tsx
import { useContext } from "react";
import { ThreadContext } from "stream-chat-react-native";

const value = useContext(ThreadContext);
```

Alternatively, use the `useThreadContext` hook.

```tsx
import { useThreadContext } from "stream-chat-react-native";

const value = useThreadContext();
```

## Values

| Value                            | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Type                                                                    |
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| `allowThreadMessagesInChannel`   | Show the _Show thread message in channel_ button in thread `MessageComposer`. Defaults to `true`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | `boolean`                                                               |
| `closeThread`                    | Unsets the thread and thread messages in the Channel state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | `function`                                                              |
| `loadMoreThread`                 | Loads more messages for the thread. Returns a promise.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | `() => Promise<void>`                                                   |
| `loadMoreRecentThread`           | Loads more recent messages for the thread. Returns a promise.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | `(opts: { limit?: number }) => Promise<void>` \| `undefined`            |
| `onAlsoSentToChannelHeaderPress` | Called when the user presses the "Also sent to channel" header on Message.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | `(payload: AlsoSentToChannelHeaderPressPayload) => void` \| `undefined` |
| `openThread`                     | Sets the thread and thread messages in the Channel state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | `function`                                                              |
| `parentMessagePreventPress`      | Boolean to enable/disable parent message press. Defaults to `true`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | `boolean`                                                               |
| `reloadThread`                   | Reloads the thread and thread messages.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | `function`                                                              |
| `setThreadLoadingMore`           | A function which can be used to set the thread loading more state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | `function`                                                              |
| `thread`                         | Can be a `LocalMessage` or [`ThreadType`](https://github.com/GetStream/stream-chat-react-native/blob/develop/package/src/contexts/threadContext/ThreadContext.tsx). Setting it indicates a thread is open. Both types are interchangeable. With [`Thread`](https://getstream.io/chat/docs/sdk/react-native/ui-components/thread/), this displays the thread. With the standard [`MessageList`](https://getstream.io/chat/docs/sdk/react-native/ui-components/message-list/), it keeps singleton components in [`OverlayProvider`](https://getstream.io/chat/docs/sdk/react-native/core-components/overlay-provider/) in sync. | `object`                                                                |
| `threadHasMore`                  | Boolean flag for thread messages pagination.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `boolean`                                                               |
| `threadInstance`                 | Instance of [`Thread`](https://github.com/GetStream/stream-chat-js/blob/master/src/thread.ts) used to read more data or pass to `onThreadSelect`.                                                                                                                                                                                                                                                                                                                                                                                                                 | `Thread`                                                                |
| `threadLoadingMore`              | Boolean flag for thread messages loading more state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | `boolean \| undefined`                                                  |
| `threadLoadingMoreRecent`        | Boolean flag for thread messages loading more recent state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | `boolean \| undefined`                                                  |
| `threadMessages`                 | A list of formatted messages objects.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | `Array<object>`                                                         |

---

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/sdk/react-native/contexts/thread-context/](https://getstream.io/chat/docs/sdk/react-native/contexts/thread-context/).