Documentation Index
Fetch the complete documentation index at: https://cometchat-22654f5b-react-uikit-v7.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
AI Integration Quick Reference
AI Integration Quick Reference
Where It Fits
CometChatUsers is a feature component that fetches and displays a paginated list of CometChat users. Wire it to CometChatMessageList via the onItemClick callback to build a one-to-one chat interface — selecting a user loads the conversation in the message pane.
Minimal Render
.cometchat-users
Usage Modes
CometChatUsers supports two modes: a Flat API for quick setup and a Compound API for full layout control.Flat API
Pass all props directly to<CometChatUsers />. The component renders its default layout (header, search bar, list, state indicators) with your customizations applied:
Compound API
UseCometChatUsers.Root with sub-components for full control over layout and which pieces render. Omit a sub-component to hide it — no boolean props needed:
State sub-components (
LoadingState, ErrorState, EmptyState) are self-managing — they read fetchState from context and automatically show/hide themselves. Place them all in the tree without conditional rendering.Sub-Components
| Component | Description |
|---|---|
CometChatUsers.Root | Calls the data hook, provides context, renders default layout when no children passed. |
CometChatUsers.Header | Header with title text. Accepts optional title and children props. |
CometChatUsers.SearchBar | Debounced search input (300ms). Accepts optional placeholder prop. |
CometChatUsers.List | User list with infinite scroll. Only renders when users are available. |
CometChatUsers.Item | Individual user row (avatar, name, status, selection control). |
CometChatUsers.SectionHeader | Alphabetical section divider (e.g., “A”, “B”). |
CometChatUsers.EmptyState | Renders when fetchState === 'empty'. Pass children for custom content. |
CometChatUsers.ErrorState | Renders when fetchState === 'error'. Pass children for custom content. |
CometChatUsers.LoadingState | Renders when fetchState === 'loading'. Pass children for custom shimmer. |
CometChatUsers.SelectedPreview | Chips showing selected users (visible in multiple selection mode). |
Filtering Users
Pass aCometChat.UsersRequestBuilder to requestBuilder. Pass the builder instance — not the result of .build().
Filter Recipes
| Recipe | Code |
|---|---|
| Limit to 50 users per page | new CometChat.UsersRequestBuilder().setLimit(50) |
| Only friends | new CometChat.UsersRequestBuilder().friendsOnly(true) |
| Filter by role | new CometChat.UsersRequestBuilder().setRoles(["admin"]) |
| Filter by status | new CometChat.UsersRequestBuilder().setStatus("online") |
| Search by keyword | new CometChat.UsersRequestBuilder().setSearchKeyword("john") |
Search Request Builder
UsesearchRequestBuilder to customize the search behavior independently from the initial fetch:
Actions and Events
Callback Props
onItemClick
Fires when a user item is clicked (inselectionMode: 'none'). Use this to drive navigation or load a conversation:
onSelect
Fires when a user is selected or deselected (insingle or multiple selection mode):
onError
Fires when an SDK fetch or listener error occurs. Use for logging or toast notifications:onEmpty
Fires when the initial fetch returns zero users:SDK Events (Real-Time, Automatic)
CometChatUsers automatically subscribes to SDK listeners for real-time updates. No manual setup required.| SDK Listener | Internal Behavior |
|---|---|
onUserOnline | Updates user status indicator to online |
onUserOffline | Updates user status indicator to offline |
onConnected | Re-initializes the request builder and re-fetches from the beginning |
In React 18 StrictMode,
useEffect runs twice on mount in development. The component handles this gracefully by using unique listener IDs per instance and cleaning up on unmount.Custom View Slots
| Slot | Signature | Replaces |
|---|---|---|
itemView | (user: CometChat.User) => ReactNode | Entire list item row |
leadingView | (user: CometChat.User) => ReactNode | Avatar |
titleView | (user: CometChat.User) => ReactNode | User name |
subtitleView | (user: CometChat.User) => ReactNode | Status text |
trailingView | (user: CometChat.User) => ReactNode | Selection control / trailing content |
headerView | ReactNode | Default header |
loadingView | ReactNode | Default shimmer |
errorView | ReactNode | Default error message |
emptyView | ReactNode | Default empty message |
subtitleView
Add custom subtitle content below the user name:itemView
Replace the entire item row with a custom component:Custom States (Compound API)
With the compound API, pass custom content as children to state sub-components:Common Patterns
Sibling Communication (Users → Messages)
Drive a message list from user selection using parent state and theonItemClick callback:
Multiple Selection with Submit
Collect selected users and submit them (e.g., for creating a group):Context Hook
Access user list state from any child rendered insideCometChatUsers.Root:
CSS Architecture
The component uses CSS custom properties (design tokens) defined in@cometchat/chat-uikit-react/css-variables.css. The cascade:
- Global tokens set on the
.cometchatroot wrapper. - Component CSS (
.cometchat-users) consumes these tokens viavar(). - Overrides target
.cometchat-usersdescendant selectors.
Key Selectors
| Target | Selector |
|---|---|
| Root container | .cometchat-users |
| Header | .cometchat-users__header |
| Search bar | .cometchat-users__search-bar |
| List container | .cometchat-users__list |
| User item | .cometchat-users__item |
| Section header | .cometchat-users__section-header |
| Empty state | .cometchat-users__empty-state |
| Error state | .cometchat-users__error-state |
| Loading state | .cometchat-users__loading-state |
| Selected preview | .cometchat-users__selected-preview |
Example: Brand-themed users list
App.css
Customization Matrix
| What to change | Where | Property/API | Example |
|---|---|---|---|
| Override behavior | Component props | onItemClick, onSelect, onError callbacks | onItemClick={(user) => navigate(user)} |
| Filter data | Component props | requestBuilder | Builder with .setRoles(["admin"]) |
| Toggle UI elements | Compound API | Omit sub-component | Remove <SearchBar /> to hide search |
| Replace UI sections | Flat API props | headerView, emptyView, loadingView | emptyView={<Custom />} |
| Change visual styling | Global CSS | .cometchat-users selectors | See CSS example above |
Props
All props are optional unless noted otherwise.requestBuilder
Custom request builder for fetching users. Controls pagination, filtering, and sorting.| Type | CometChat.UsersRequestBuilder |
| Default | Internal builder with limit 30 |
searchRequestBuilder
Custom request builder used specifically for search queries. When the user types in the search bar, this builder is used instead ofrequestBuilder.
| Type | CometChat.UsersRequestBuilder |
| Default | undefined |
searchKeyword
Initial search keyword to pre-filter the user list on mount.| Type | string |
| Default | "" |
hideUserStatus
Hide the online/offline status indicator dot on user items.| Type | boolean |
| Default | false |
selectionMode
Controls selection behavior and the UI controls shown on each item.| Type | 'none' | 'single' | 'multiple' |
| Default | 'none' |
'none': No selection controls. Clicking triggersonItemClick.'single': Radio buttons appear. One user selectable at a time.'multiple': Checkboxes appear. Supports shift-click range selection.
activeUser
The currently highlighted user. The matching item receives an active visual state.| Type | CometChat.User |
| Default | undefined |
sectionHeaderKey
The property used to extract alphabetical section headers from each user object.| Type | keyof CometChat.User |
| Default | 'getName' |
options
Function that returns context menu options for each user. Options appear on hover/long-press.| Type | (user: CometChat.User) => CometChatUserOption[] |
| Default | undefined |
onItemClick
Callback when a user item is clicked (only fires inselectionMode: 'none'). Use for sibling component communication.
| Type | (user: CometChat.User) => void |
| Default | undefined |
onSelect
Callback when a user is selected or deselected (fires insingle or multiple mode).
| Type | (user: CometChat.User, selected: boolean) => void |
| Default | undefined |
onError
Callback when an error occurs during fetch or real-time listener operations.| Type | (error: unknown) => void |
| Default | undefined |
onEmpty
Callback when the initial fetch returns zero users.| Type | () => void |
| Default | undefined |
showScrollbar
Whether to show the native scrollbar on the list. Whenfalse, the scrollbar is hidden via CSS but scrolling still works.
| Type | boolean |
| Default | false |
leadingView
Custom leading view per user item. Replaces the default avatar.| Type | (user: CometChat.User) => ReactNode |
| Default | undefined |
titleView
Custom title view per user item. Replaces the user name.| Type | (user: CometChat.User) => ReactNode |
| Default | undefined |
subtitleView
Custom subtitle view per user item. Renders below the title.| Type | (user: CometChat.User) => ReactNode |
| Default | undefined |
trailingView
Custom trailing view per user item. Replaces the selection control in selection modes.| Type | (user: CometChat.User) => ReactNode |
| Default | undefined |
itemView
Fully custom item renderer. OverridesleadingView, titleView, subtitleView, and trailingView.
| Type | (user: CometChat.User) => ReactNode |
| Default | undefined |
headerView
Custom header content. Replaces the default header entirely.| Type | ReactNode |
| Default | undefined |
loadingView
Custom loading state content. Replaces the default shimmer animation.| Type | ReactNode |
| Default | undefined |
errorView
Custom error state content. Replaces the default error message.| Type | ReactNode |
| Default | undefined |
emptyView
Custom empty state content. Replaces the default “no users” message.| Type | ReactNode |
| Default | undefined |
CSS Selectors
| Target | Selector |
|---|---|
| Root | .cometchat-users |
| Header | .cometchat-users__header |
| Header title | .cometchat-users__header-title |
| Search bar | .cometchat-users__search-bar |
| List | .cometchat-users__list |
| Item | .cometchat-users__item |
| Item (active) | .cometchat-users__item--active |
| Item avatar | .cometchat-users__item-avatar |
| Item name | .cometchat-users__item-name |
| Item status | .cometchat-users__item-status |
| Section header | .cometchat-users__section-header |
| Empty state | .cometchat-users__empty-state |
| Error state | .cometchat-users__error-state |
| Loading state | .cometchat-users__loading-state |
| Selected preview | .cometchat-users__selected-preview |
| Selected chip | .cometchat-users__selected-chip |
Accessibility
- List container:
role="listbox"witharia-label="Users list" - User items:
role="option"witharia-selected - Section headers:
role="separator"witharia-label - Loading state:
aria-busy="true" - Keyboard:
Tabto focus,ArrowUp/ArrowDownto navigate,Enter/Spaceto select,Escapeto clear search - All icon-only buttons have
aria-label :focus-visiblestyles on all interactive elements