Skip to main content

Where It Fits

CometChatGroups is a directory list component. It renders available groups and emits the selected CometChat.Group via onItemClick. Wire it to CometChatMessageHeader, CometChatMessageList, and CometChatMessageComposer to build a group chat layout.

Minimal Render

Root CSS class: .cometchat-groups

Filtering Groups

Pass a CometChat.GroupsRequestBuilder to groupsRequestBuilder. Pass the builder instance — not the result of .build().

Filter Recipes

RecipeCode
Joined groups onlynew CometChat.GroupsRequestBuilder().joinedOnly(true)
Limit to 10 per pagenew CometChat.GroupsRequestBuilder().setLimit(10)
Search by keywordnew CometChat.GroupsRequestBuilder().setSearchKeyword("design")
Filter by tagsnew CometChat.GroupsRequestBuilder().setTags(["vip"])
With tags datanew CometChat.GroupsRequestBuilder().withTags(true)
Default page size is 30. The component uses infinite scroll — the next page loads as the user scrolls to the bottom. The searchRequestBuilder prop accepts a separate GroupsRequestBuilder for filtering when the search bar is active.
Refer to GroupsRequestBuilder for the full builder API.

Actions and Events

Callback Props

onItemClick

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

onSelect

Fires when a group is checked/unchecked in multi-select mode. Requires selectionMode to be set.

onError

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

Global UI Events

CometChatGroupEvents emits events subscribable from anywhere in the application. Subscribe in a useEffect and unsubscribe on cleanup.
EventFires whenPayload
ccGroupCreatedA new group is createdCometChat.Group
ccGroupDeletedA group is deletedCometChat.Group
ccGroupMemberJoinedA user joins a groupIGroupMemberJoined
ccGroupLeftA user leaves a groupIGroupLeft
ccGroupMemberAddedMembers are added to a groupIGroupMemberAdded
ccGroupMemberScopeChangedA member’s scope changesIGroupMemberScopeChanged
ccGroupMemberKickedA member is kickedIGroupMemberKickedBanned
ccGroupMemberBannedA member is bannedIGroupMemberKickedBanned
ccGroupMemberUnbannedA member is unbannedIGroupMemberUnBanned
ccOwnershipChangedGroup ownership is transferredIOwnershipChanged

SDK Events (Real-Time, Automatic)

The component listens to these SDK events internally. No manual attachment needed unless additional side effects are required.
SDK ListenerInternal behavior
onGroupMemberJoinedUpdates member count, sets hasJoined if current user joined
onGroupMemberLeftUpdates member count, sets hasJoined(false) if current user left
onMemberAddedToGroupUpdates member count, adds group to list if current user was added
onGroupMemberKickedUpdates member count, sets hasJoined(false) if current user was kicked
onGroupMemberBannedRemoves group if current user was banned, otherwise updates member count
onGroupMemberScopeChangedUpdates scope if current user’s scope changed, updates member count
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 group parameter receive the CometChat.Group object for that row.
SlotSignatureReplaces
itemView(group: CometChat.Group) => JSX.ElementEntire list item row
leadingView(group: CometChat.Group) => JSX.ElementAvatar / left section
titleView(group: CometChat.Group) => JSX.ElementName / title text
subtitleView(group: CometChat.Group) => JSX.ElementMember count subtitle
trailingView(group: CometChat.Group) => JSX.ElementRight section
headerViewJSX.ElementEntire header bar
loadingViewJSX.ElementLoading spinner
emptyViewJSX.ElementEmpty state
errorViewJSX.ElementError state
options(group: CometChat.Group) => CometChatOption[]Context menu / hover actions

itemView

Replace the entire list item row. Default:
Customized:

titleView

Replace the name / title text. Group type badge inline example.

subtitleView

Replace the member count subtitle text. Default:
Customized:

leadingView

Replace the avatar / left section. Joined status badge example.

trailingView

Replace the right section. Join status button example.

headerView

Replace the entire header bar.

options

Replace the context menu / hover actions on each group item.

Common Patterns

Custom empty state with CTA

Hide all chrome — minimal list

Joined groups only


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-groups) consumes these tokens via var() with fallback values.
  3. Overrides target .cometchat-groups descendant selectors in a global stylesheet.
To scope overrides to a single instance when multiple CometChatGroups exist on the same page, wrap the component in a container and scope selectors:

Key Selectors

TargetSelector
Root.cometchat-groups
Header title.cometchat-groups .cometchat-list__header-title
Search bar input.cometchat-groups .cometchat-search-bar__input
List item.cometchat-groups .cometchat-list-item
Body title.cometchat-groups .cometchat-list-item__body-title
Avatar.cometchat-groups__list-item .cometchat-avatar
Subtitle.cometchat-groups__subtitle
Active item.cometchat-groups__list-item-active .cometchat-list-item
Password group icon.cometchat-groups__list-item-password .cometchat-list-item__status
Private group icon.cometchat-groups__list-item-private .cometchat-list-item__status
Empty state.cometchat-groups__empty-state-view
Error state.cometchat-groups__error-state-view
Shimmer loading.cometchat-groups__shimmer

Example: Brand-themed groups

Customization Matrix

What to changeWhereProperty/APIExample
Override behavior on user interactionComponent propson<Event> callbacksonItemClick={(g) => setActive(g)}
Filter which groups appearComponent propsgroupsRequestBuildergroupsRequestBuilder={new CometChat.GroupsRequestBuilder().joinedOnly(true)}
Toggle visibility of UI elementsComponent propshide<Feature> boolean propshideGroupType={true}
Replace a section of the list itemComponent props<slot>View render propsitemView={(group) => <div>...</div>}
Change colors, fonts, spacingGlobal CSSTarget .cometchat-groups class.cometchat-groups .cometchat-avatar { border-radius: 8px; }

Props

All props are optional unless noted otherwise.

activeGroup

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

emptyView

Custom component displayed when there are no groups.
TypeJSX.Element
DefaultBuilt-in empty state

errorView

Custom component displayed when an error occurs.
TypeJSX.Element
DefaultBuilt-in error state
Hidden when hideError={true}.

groupsRequestBuilder

Controls which groups load and in what order.
TypeCometChat.GroupsRequestBuilder
DefaultSDK default (30 per page)
Pass the builder instance, not the result of .build().

headerView

Custom component rendered as the entire header bar.
TypeJSX.Element
DefaultBuilt-in header with title

hideError

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

hideGroupType

Hides the group type icon (public/private/password).
Typeboolean
Defaultfalse

hideSearch

Hides the default search bar.
Typeboolean
Defaultfalse

itemView

Custom renderer for the entire list item row.
Type(group: CometChat.Group) => JSX.Element
DefaultBuilt-in list item

leadingView

Custom renderer for the avatar / left section.
Type(group: CometChat.Group) => JSX.Element
DefaultBuilt-in avatar

loadingView

Custom component displayed during the loading state.
TypeJSX.Element
DefaultBuilt-in shimmer

onError

Callback fired when the component encounters an error.
Type((error: CometChat.CometChatException) => void) | null
Defaultundefined

onItemClick

Callback fired when a group row is clicked.
Type(group: CometChat.Group) => void
Defaultundefined

onSelect

Callback fired when a group is selected/deselected. Requires selectionMode to be set.
Type(group: CometChat.Group, selected: boolean) => void
Defaultundefined

options

Custom context menu / hover actions for each group item.
Type(group: CometChat.Group) => CometChatOption[]
Defaultundefined

searchRequestBuilder

Controls filtering when the search bar is active.
TypeCometChat.GroupsRequestBuilder
Defaultundefined

selectionMode

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

showScrollbar

Shows the scrollbar in the group list.
Typeboolean
Defaultfalse

subtitleView

Custom renderer for the member count subtitle text.
Type(group: CometChat.Group) => JSX.Element
DefaultBuilt-in subtitle

titleView

Custom renderer for the name / title text.
Type(group: CometChat.Group) => JSX.Element
DefaultBuilt-in title

trailingView

Custom renderer for the right section.
Type(group: CometChat.Group) => JSX.Element
DefaultBuilt-in trailing view

Events

EventPayloadFires when
CometChatGroupEvents.ccGroupCreatedCometChat.GroupNew group created
CometChatGroupEvents.ccGroupDeletedCometChat.GroupGroup deleted
CometChatGroupEvents.ccGroupMemberJoinedIGroupMemberJoinedUser joins a group
CometChatGroupEvents.ccGroupLeftIGroupLeftUser leaves a group
CometChatGroupEvents.ccGroupMemberAddedIGroupMemberAddedMembers added to a group
CometChatGroupEvents.ccGroupMemberScopeChangedIGroupMemberScopeChangedMember scope changed
CometChatGroupEvents.ccGroupMemberKickedIGroupMemberKickedBannedMember kicked
CometChatGroupEvents.ccGroupMemberBannedIGroupMemberKickedBannedMember banned
CometChatGroupEvents.ccGroupMemberUnbannedIGroupMemberUnBannedMember unbanned
CometChatGroupEvents.ccOwnershipChangedIOwnershipChangedOwnership transferred
All events are RxJS Subject instances. Subscribe with .subscribe(), unsubscribe with the returned subscription’s .unsubscribe().

CSS Selectors

TargetSelector
Root.cometchat-groups
Header title.cometchat-groups .cometchat-list__header-title
Search bar input.cometchat-groups .cometchat-search-bar__input
List item.cometchat-groups .cometchat-list-item
Body title.cometchat-groups .cometchat-list-item__body-title
Avatar.cometchat-groups__list-item .cometchat-avatar
Leading view.cometchat-groups__list-item .cometchat-list-item__leading-view
Subtitle.cometchat-groups__subtitle
Active item.cometchat-groups__list-item-active .cometchat-list-item
Password group icon.cometchat-groups__list-item-password .cometchat-list-item__status
Password group status icon.cometchat-groups__list-item-password .cometchat-list-item__status-icon
Private group icon.cometchat-groups__list-item-private .cometchat-list-item__status
Private group status icon.cometchat-groups__list-item-private .cometchat-list-item__status-icon
Empty state.cometchat-groups__empty-state-view
Empty state title.cometchat-groups__empty-state-view-body-title
Empty state description.cometchat-groups__empty-state-view-body-description
Error state.cometchat-groups__error-state-view
Error state title.cometchat-groups__error-state-view-body-title
Error state description.cometchat-groups__error-state-view-body-description
Shimmer loading.cometchat-groups__shimmer
Shimmer item.cometchat-groups__shimmer-item
Shimmer avatar.cometchat-groups__shimmer-item-avatar
Shimmer title.cometchat-groups__shimmer-item-body-title
Shimmer subtitle.cometchat-groups__shimmer-item-body-subtitle