Skip to content

Commit 4f91d9a

Browse files
authored
feat: allow to configure channel query options (#2177)
1 parent 25e66dc commit 4f91d9a

File tree

4 files changed

+166
-83
lines changed

4 files changed

+166
-83
lines changed

docusaurus/docs/React/components/core-components/channel.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,39 @@ Custom UI component to display a user's avatar.
176176
| --------- | ---------------------------------------------------------- |
177177
| component | <GHComponentLink text='Avatar' path='/Avatar/Avatar.tsx'/> |
178178

179+
### channelQueryOptions
180+
181+
Optional configuration parameters used for the initial channel query. Applied only if the value of `channel.initialized` is false. If the channel instance has already been initialized (channel has been queried), then the channel query will be skipped and channelQueryOptions will not be applied.
182+
183+
In the example below, we specify, that the first page of messages when a channel is queried should have 20 messages (the default is 100). Note that the `channel` prop has to be passed along `channelQueryOptions`.
184+
185+
```tsx
186+
import {ChannelQueryOptions} from "stream-chat";
187+
import {Channel, useChatContext} from "stream-chat-react";
188+
189+
const channelQueryOptions: ChannelQueryOptions = {
190+
messages: { limit: 20 },
191+
};
192+
193+
type ChannelRendererProps = {
194+
id: string;
195+
type: string;
196+
};
197+
198+
const ChannelRenderer = ({id, type}: ChannelRendererProps) => {
199+
const { client } = useChatContext();
200+
return (
201+
<Channel channel={client.channel(type, id)} channelQueryOptions={channelQueryOptions}>
202+
{/* Channel children */}
203+
</Channel>
204+
);
205+
}
206+
```
207+
208+
| Type |
209+
|-----------------------|
210+
| `ChannelQueryOptions` |
211+
179212
### CooldownTimer
180213

181214
Custom UI component to display the slow mode cooldown timer.

0 commit comments

Comments
 (0)