Skip to main content

Where It Fits

CometChatUsers is a contact list component. It renders all available users and emits the selected CometChat.User via onItemClick. Wire it to CometChatMessageHeader, CometChatMessageList, and CometChatMessageComposer to build a standard two-panel chat layout.

Minimal Render

Root CSS class: .cometchat-users

Filtering Users

Pass a CometChat.UsersRequestBuilder to usersRequestBuilder. Pass the builder instance — not the result of .build().

Filter Recipes

Default page size is 30. The component uses infinite scroll — the next page loads as the user scrolls to the bottom. A separate searchRequestBuilder can be passed to filter the search list independently from the main list. Refer to UsersRequestBuilder for the full builder API.

Actions and Events

Callback Props

onItemClick

Fires when a user row is tapped. Primary navigation hook — set the active user and render the message view.

onSelect

Fires when a user is checked/unchecked in selection mode. Requires selectionMode to be set.

onEmpty

Fires when the user list fetch returns zero results.

onError

Fires on internal errors (network failure, auth issue, SDK exception).

Global UI Events

The component subscribes to CometChatUserEvents internally: CometChatUsers does not emit any custom UI events.

SDK Events (Real-Time, Automatic)

The component listens to these SDK events internally. No manual attachment needed unless additional side effects are required. Automatic: user presence changes (online/offline), blocked/unblocked state.
In React 18 StrictMode, useEffect runs twice on mount in development. The component handles listener cleanup internally, but any additional listeners added alongside the component need cleanup in the useEffect return function to avoid duplicate event handling.

Custom View Slots

Each slot replaces a section of the default UI. Slots that accept a user parameter receive the CometChat.User object for that row.

itemView

Replace the entire list item row. Default:
Customized:

leadingView

Replace the avatar / left section.

trailingView

Replace the right section.

titleView

Replace the name / title text. Role badge inline example.

subtitleView

Replace the subtitle text for each user. Default:
Customized:

headerView

Replace the entire header bar.

options

Replace the context menu / hover actions on each user item. Default:
Customized:

Common Patterns

Custom empty state with CTA

Multi-select with preview strip

Hide all chrome — minimal list


CSS Architecture

The component uses CSS custom properties (design tokens) defined in @cometchat/chat-uikit-react/css-variables.css. The cascade:
  1. Global tokens (e.g., --cometchat-primary-color, --cometchat-background-color-01) are set on the .cometchat root wrapper.
  2. Component CSS (.cometchat-users) consumes these tokens via var() with fallback values.
  3. Overrides target .cometchat-users descendant selectors in a global stylesheet.
To scope overrides to a single instance when multiple CometChatUsers exist on the same page, wrap the component in a container and scope selectors:
Overrides survive component updates because the component never sets inline styles on these elements — all styling flows through CSS classes and custom properties.

Key Selectors

Example: Brand-themed users

Customization Matrix


Props

All props are optional unless noted.

activeUser

Highlights the specified user in the list. Must be a reference-equal object from the SDK; a manually constructed object will not match.

disableLoadingState

Disables the loading state while fetching users. Useful when updating the request builder without clearing the list.

emptyView

Custom component displayed when there are no users.

errorView

Custom component displayed when an error occurs. Hidden when hideError={true}.

headerView

Custom component rendered as the entire header bar.

hideError

Hides the default and custom error views. Also suppresses errorView if set.

hideSearch

Hides the default search bar.

hideUserStatus

Hides the online/offline status indicator.

itemView

Custom renderer for the entire list item row.

leadingView

Custom renderer for the avatar / left section.

loadingView

Custom component displayed during the loading state.

onEmpty

Callback fired when the user list is empty.

onError

Callback fired when the component encounters an error.

onItemClick

Callback fired when a user row is clicked.

onSelect

Callback fired when a user is selected/deselected. Requires selectionMode to be set.

options

Custom context menu / hover actions for each user item.

searchKeyword

Pre-fills the search and filters the user list.

searchRequestBuilder

Request builder with search parameters to fetch users. If the search input is not empty, the search keyword of this request builder is set to the text in the search input.

sectionHeaderKey

The property on the user object used to extract the section header character. Only relevant when showSectionHeader={true}.

selectionMode

Enables single or multi-select checkboxes on list items.
Must pair with onSelect to capture selections.

showScrollbar

Shows the scrollbar in the user list.

showSectionHeader

Displays alphabetical section headers (A, B, C…).

showSelectedUsersPreview

Shows a preview strip of selected users when selectionMode is multiple. Each chip displays avatar, name, and a close button to remove the user.

subtitleView

Custom renderer for the subtitle text.

titleView

Custom renderer for the name / title text.

trailingView

Custom renderer for the right section.

usersRequestBuilder

Controls which users load and in what order. Pass the builder instance, not the result of .build().

Events

CometChatUsers does not emit custom UI events. It subscribes to:

CSS Selectors