Skip to main content

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.

{
  "component": "CometChatUsers",
  "package": "@cometchat/chat-uikit-react",
  "import": "import { CometChatUsers } from \"@cometchat/chat-uikit-react\";",
  "cssImport": "import \"@cometchat/chat-uikit-react/css-variables.css\";",
  "description": "Searchable, scrollable list of users with selection support and real-time presence updates.",
  "cssRootClass": ".cometchat-users",
  "primaryOutput": {
    "prop": "onItemClick",
    "type": "(user: CometChat.User) => void"
  },
  "props": {
    "data": {
      "usersRequestBuilder": {
        "type": "CometChat.UsersRequestBuilder",
        "default": "SDK default (30 per page)",
        "note": "Pass the builder instance, not the result of .build()"
      },
      "searchRequestBuilder": {
        "type": "CometChat.UsersRequestBuilder",
        "default": "undefined"
      },
      "searchKeyword": {
        "type": "string",
        "default": "undefined"
      },
      "activeUser": {
        "type": "CometChat.User",
        "default": "undefined"
      },
      "sectionHeaderKey": {
        "type": "keyof CometChat.User",
        "default": "undefined"
      }
    },
    "callbacks": {
      "onItemClick": "(user: CometChat.User) => void",
      "onSelect": "(user: CometChat.User, selected: boolean) => void",
      "onError": "((error: CometChat.CometChatException) => void) | null",
      "onEmpty": "() => void"
    },
    "visibility": {
      "hideUserStatus": { "type": "boolean", "default": false },
      "hideSearch": { "type": "boolean", "default": false },
      "showSectionHeader": { "type": "boolean", "default": true },
      "showSelectedUsersPreview": { "type": "boolean", "default": false },
      "showScrollbar": { "type": "boolean", "default": false }
    },
    "selection": {
      "selectionMode": {
        "type": "CometChatUsersSelectionMode",
        "values": ["'none'", "'single'", "'multiple'"],
        "default": "'none'"
      }
    },
    "viewSlots": {
      "itemView": "(user: CometChat.User) => ReactNode",
      "leadingView": "(user: CometChat.User) => ReactNode",
      "titleView": "(user: CometChat.User) => ReactNode",
      "subtitleView": "(user: CometChat.User) => ReactNode",
      "trailingView": "(user: CometChat.User) => ReactNode",
      "headerView": "ReactNode",
      "loadingView": "ReactNode",
      "emptyView": "ReactNode",
      "errorView": "ReactNode",
      "options": "(user: CometChat.User) => CometChatUserOption[]"
    }
  },
  "events": [],
  "eventsReceived": [
    {
      "name": "ui:user/blocked",
      "payload": "{ user: CometChat.User }",
      "description": "Updates user in the list (shows blocked state)"
    },
    {
      "name": "ui:user/unblocked",
      "payload": "{ user: CometChat.User }",
      "description": "Updates user in the list (removes blocked state)"
    }
  ],
  "sdkListeners": [
    "onUserOnline",
    "onUserOffline"
  ],
  "types": {
    "CometChatUserOption": {
      "id": "string",
      "title": "string",
      "iconURL": "string | undefined",
      "onClick": "(user: CometChat.User) => void"
    },
    "CometChatUsersSelectionMode": "'none' | 'single' | 'multiple'"
  }
}

Overview

CometChatUsers is a list component that renders all available users in the app. It emits the selected CometChat.User via onItemClick. Wire it to CometChatMessages or use it as a user picker in flows like “new conversation” or “add members to group.”
Live Preview — interact with the default users list.Open in Storybook ↗
The component handles:
  • Paginated fetching with infinite scroll
  • Real-time presence updates (online/offline)
  • Search filtering
  • Alphabetical section headers
  • Selection mode (single/multiple) with optional preview chips

Usage

Flat API

import { CometChatUsers } from "@cometchat/chat-uikit-react";

function UserPicker() {
  return (
    <CometChatUsers
      onItemClick={(user) => {
        console.log("Selected user:", user.getName());
      }}
    />
  );
}

Compound Composition

import { CometChatUsers } from "@cometchat/chat-uikit-react";

function UserPicker() {
  return (
    <CometChatUsers.Root onItemClick={handleClick}>
      <CometChatUsers.Header title="Users" />
      <CometChatUsers.SearchBar placeholder="Search users..." />
      <CometChatUsers.LoadingState />
      <CometChatUsers.ErrorState />
      <CometChatUsers.EmptyState>
        <p>No users found.</p>
      </CometChatUsers.EmptyState>
      <CometChatUsers.List />
    </CometChatUsers.Root>
  );
}

New Conversation Example

import { useState } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
  CometChatUsers,
  CometChatMessageHeader,
  CometChatMessageList,
  CometChatMessageComposer,
} from "@cometchat/chat-uikit-react";

function NewChat() {
  const [user, setUser] = useState<CometChat.User | undefined>();

  return (
    <div style={{ display: "flex", height: "100vh" }}>
      <div style={{ width: 360 }}>
        <CometChatUsers onItemClick={(u) => setUser(u)} activeUser={user} />
      </div>
      {user && (
        <div style={{ flex: 1, display: "flex", flexDirection: "column" }}>
          <CometChatMessageHeader user={user} />
          <CometChatMessageList user={user} />
          <CometChatMessageComposer user={user} />
        </div>
      )}
    </div>
  );
}

Filtering

Pass a CometChat.UsersRequestBuilder to usersRequestBuilder to control which users load. Pass the builder instance — not the result of .build().
<CometChatUsers
  usersRequestBuilder={
    new CometChat.UsersRequestBuilder()
      .setLimit(15)
      .setStatus("online")
  }
/>
The component includes a built-in search bar. When the user types, it fetches matching users from the server. For custom search behavior, pass a searchRequestBuilder:
<CometChatUsers
  searchRequestBuilder={
    new CometChat.UsersRequestBuilder().setLimit(30).setSearchKeyword("")
  }
/>

Filter Recipes

RecipeCode
Only online usersnew CometChat.UsersRequestBuilder().setStatus("online")
Only friendsnew CometChat.UsersRequestBuilder().friendsOnly(true)
Limit page sizenew CometChat.UsersRequestBuilder().setLimit(10)
By rolenew CometChat.UsersRequestBuilder().setRoles(["admin"])
With tagsnew CometChat.UsersRequestBuilder().setTags(["vip"])
Hide blockednew CometChat.UsersRequestBuilder().hideBlockedUsers(true)

Actions and Events

Callback Props

PropSignatureFires when
onItemClick(user: CometChat.User) => voidUser clicks a user item
onSelect(user: CometChat.User, selected: boolean) => voidUser selected/deselected (selection mode)
onError((error: CometChat.CometChatException) => void) | nullSDK error occurs
onEmpty() => voidList is empty after initial fetch

Events Emitted

This component does not emit any UI events.

Events Received

UI events this component subscribes to (published by other components):
EventPayloadBehavior
ui:user/blocked{ user }Updates user in the list (shows blocked state)
ui:user/unblocked{ user }Updates user in the list (removes blocked state)

SDK Listeners (Automatic)

These SDK listeners are attached internally. The component updates its state automatically — no manual subscription needed:
  • Presence: onUserOnline, onUserOffline

Customization

View Props

Use view props to replace sections of the default UI while keeping the component’s behavior intact:
<CometChatUsers
  headerView={<MyCustomHeader />}
  itemView={(user) => <MyCustomUserItem user={user} />}
  emptyView={<EmptyState />}
  loadingView={<Skeleton />}
  errorView={<ErrorBanner />}
/>
SlotSignatureReplaces
itemView(user) => ReactNodeEntire user row
leadingView(user) => ReactNodeAvatar section
titleView(user) => ReactNodeUser name
subtitleView(user) => ReactNodeStatus text
trailingView(user) => ReactNodeTrailing content
headerViewReactNodeHeader area
loadingViewReactNodeLoading shimmer
emptyViewReactNodeEmpty state
errorViewReactNodeError state

Compound Composition

For full layout control, use sub-components. Omit any sub-component to hide it:
<CometChatUsers.Root onItemClick={handleClick}>
  {/* No Header or SearchBar — they won't render */}
  <CometChatUsers.List />
</CometChatUsers.Root>
Available sub-components:
Sub-componentDescriptionPropsFlat API equivalent
RootContext provider and containerAll Root props + children
ListScrollable user listitemView, classNameitemView
ItemIndividual user rowleadingView, titleView, subtitleView, trailingView, classNamePer-item view props
HeaderHeader areatitle, childrenheaderView
SearchBarSearch inputplaceholder
SectionHeaderAlphabetical section headerletter
EmptyStateEmpty statechildrenemptyView
ErrorStateError statechildrenerrorView
LoadingStateLoading shimmerchildrenloadingView
SelectedPreviewSelected users chip barchipView

CSS Styling

Override design tokens on the component selector:
.cometchat-users {
  --cometchat-background-color-01: #1a1a2e;
  --cometchat-text-color-primary: #ffffff;
}

.cometchat-users__item--active {
  background: var(--cometchat-primary-color);
}

Props

All props are optional.
View slot props (headerView, searchView, loadingView, emptyView, errorView, itemView, leadingView, titleView, subtitleView, trailingView) are convenience props available only on the flat API. In compound composition mode, use the corresponding sub-components directly.

usersRequestBuilder

Custom request builder for fetching users. Controls pagination, filtering, and sorting.
TypeCometChat.UsersRequestBuilder
DefaultSDK default (limit 30)

searchRequestBuilder

Custom request builder used specifically when the user searches. Separate from the main builder.
TypeCometChat.UsersRequestBuilder
Defaultundefined

searchKeyword

Initial search keyword to pre-filter users on mount.
Typestring
Defaultundefined

hideUserStatus

Hide the online/offline status indicator on user avatars.
Typeboolean
Defaultfalse

hideSearch

Hide the search bar entirely.
Typeboolean
Defaultfalse

showSectionHeader

Show alphabetical section headers (A, B, C…) in the user list.
Typeboolean
Defaulttrue

showSelectedUsersPreview

Show a preview strip of selected user chips above the list (useful in multi-select mode).
Typeboolean
Defaultfalse

showScrollbar

Show the native scrollbar on the user list.
Typeboolean
Defaultfalse

selectionMode

Enable selection mode for single or multi-select operations.
Type'none' | 'single' | 'multiple'
Default'none'

activeUser

The currently active/highlighted user. The matching item receives an active visual state.
TypeCometChat.User
Defaultundefined

sectionHeaderKey

The property of CometChat.User used to group users into sections (e.g., first letter of name).
Typekeyof CometChat.User
Defaultundefined

options

Function that returns context menu options for each user item (shown on hover/swipe).
Type(user: CometChat.User) => CometChatUserOption[]
Defaultundefined
<CometChatUsers
  options={(user) => [
    {
      id: "block",
      title: "Block User",
      iconURL: blockIcon,
      onClick: (u) => blockUser(u),
    },
    {
      id: "info",
      title: "View Profile",
      iconURL: infoIcon,
      onClick: (u) => openProfile(u),
    },
  ]}
/>

onItemClick

Callback when a user item is clicked.
Type(user: CometChat.User) => void
Defaultundefined

onSelect

Callback when a user is selected or deselected (only fires in selection mode).
Type(user: CometChat.User, selected: boolean) => void
Defaultundefined

onError

Callback when an SDK error occurs during fetch or real-time operations.
Type((error: CometChat.CometChatException) => void) | null
Defaultnull

onEmpty

Callback when the user list is empty after the initial fetch completes.
Type() => void
Defaultundefined

CSS Selectors

TargetSelector
Root container.cometchat-users
Header.cometchat-users__header
Search bar.cometchat-users__search-bar
List container.cometchat-users__list
User item.cometchat-users__item
Active item.cometchat-users__item--active
Section header.cometchat-users__section-header
Empty state.cometchat-users__empty-state
Error state.cometchat-users__error-state
Loading state.cometchat-users__loading-state

Next Steps

Conversations

View recent conversations for the logged-in user

Groups

Browse and join groups

Message List

Display messages for the selected user

Theming

Customize colors, fonts, and spacing