import { useContext } from "react";
import { ThreadContext } from "stream-chat-react-native";
const value = useContext(ThreadContext);ThreadContext
ThreadContext is provided by Channel. If you are not familiar with the React Context API, see the React docs.
Best Practices
- Use
useThreadContextfor consistent access and typings. - Manage thread navigation via
openThread/closeThreadrather than manual state. - Use
threadHasMoreandthreadLoadingMoreto 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:
Alternatively, use the useThreadContext hook.
import { useThreadContext } from "stream-chat-react-native";
const value = useThreadContext();Value
allowThreadMessagesInChannel
Show the Show thread message in channel button in thread MessageInput.
| Type | Default |
|---|---|
| boolean | true |
closeThread
Unsets the thread and thread messages in the Channel state.
| Type |
|---|
| Function |
loadMoreThread
Loads more messages for the thread. Returns a promise.
| Type |
|---|
() => Promise<void> |
openThread
Sets the thread and thread messages in the Channel state.
| Type |
|---|
| function |
parentMessagePreventPress
Boolean to enable/disable parent message press.
| Type | Default |
|---|---|
| Boolean | true |
reloadThread
Reloads the thread and thread messages.
| Type |
|---|
| function |
setThreadLoadingMore
A function which can be used to set the thread loading more state.
| Type |
|---|
| function |
thread
Can be a LocalMessage or ThreadType. Setting it indicates a thread is open. Both types are interchangeable.
With Thread, this displays the thread. With the standard MessageList, it keeps singleton components in OverlayProvider in sync.
Set thread on all Channel components when a thread is open.
| Type |
|---|
| object |
threadHasMore
Boolean flag for thread messages pagination.
| Type |
|---|
| boolean |
threadLoadingMore
Boolean flag for thread messages loading more state.
| Type |
|---|
| boolean |
threadMessages
A list of formatted messages objects.
| Type |
| --------------- | --- |
| Array<object> | |