For AI agents: this page in Markdown: https://www.pubnub.com/docs/chat/components/react-native/custom-hooks/use-channels.md. Documentation index: https://www.pubnub.com/llms-full.txt.
useChannels for PubNub Chat Components for React Native
USED BY THE OLD IA, PLEASE DISREGARD
The hook returns a list of channel metadata objects, optionally including the custom data object for each.
Pagination is handled internally. You can adjust the limit of returned channels on a single call (max/default 100) and call a function returned by the hook to get another page of results. This hook also sets up a listener that reacts to updates and removals of already fetched channels.
However, this behavior requires a living subscription to channels getting updated - this should be handled by the components.
1const [channels, fetchPage, total, error, isLoading] = useChannels();
2
3return (
4 <Chat {...{ options }}>
5 <ChannelList channels={channels} />
6 </Chat>
7);
Input
* required
| Parameter | Defaults | Description |
|---|---|---|
includeType: Object | n/a | Option to include respective additional fields in the response. |
→ customFieldsType: Boolean | false | Option to fetch custom fields or not. |
filterType: String | n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. See the App Context Filtering Language Definition for more details. |
sortType: Object | n/a | Key-value pair of a property to sort by and a sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). Example: {name: 'asc'} |
limitType: Number | 100 | Number of objects to return in response. Default is 100 which is also the maximum value. |
Output
| Parameter | Description |
|---|---|
array[0]Type: ChannelData[] | List of returned channels. |
array[1]Type: Function | Function that can be called to fetch another page of channels. |
array[2]Type: Number | Total number of stored channels. |
array[3]Type: Error | If there's an error fetching channels, it will be available here. |
array[4]Type: Boolean | Indicator that the channel data is still being loaded. |