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.

Overview

CometChatGroups displays a real-time list of groups in your CometChat app. It supports infinite scroll pagination, search with debounce, group type indicators (public/private/password-protected), single/multiple selection modes with shift-click range selection, and group mutations (create, join, leave, delete). It offers two usage modes:
  • Flat API — pass convenience props directly to <CometChatGroups /> for quick customization
  • Compound API — use <CometChatGroups.Root> with sub-components for full layout control

Import

import { CometChatGroups } from '@cometchat/chat-uikit-react';

Quick Start

Flat API (Simple)

The flat API is the simplest way to render a group list. Pass props directly to <CometChatGroups />:
<CometChatGroups
  onItemClick={(group) => console.log('Selected:', group.getName())}
  subtitleView={(group) => <span>{group.getMembersCount()} members</span>}
/>

Compound API (Advanced)

Use the compound API for full control over layout and rendering. Place only the sub-components you need inside <CometChatGroups.Root>:
<CometChatGroups.Root selectionMode="multiple" onSelect={handleSelect}>
  <CometChatGroups.Header />
  <CometChatGroups.SearchBar />
  <CometChatGroups.LoadingState />
  <CometChatGroups.ErrorState />
  <CometChatGroups.EmptyState />
  <CometChatGroups.List />
</CometChatGroups.Root>
State sub-components (LoadingState, ErrorState, EmptyState) are self-managing — they read fetchState from context and automatically show/hide themselves. You don’t need conditional rendering.

Sub-Components

ComponentDescription
CometChatGroups.RootProvider + default layout. Wraps children with context.
CometChatGroups.HeaderHeader with title text (defaults to “Groups”).
CometChatGroups.SearchBarDebounced search input (300ms).
CometChatGroups.ListGroup list with infinite scroll. Self-manages visibility based on fetch state.
CometChatGroups.ItemIndividual group item (avatar, name, member count, type badge, selection control).
CometChatGroups.EmptyStateSelf-managing — only renders when fetchState === 'empty'.
CometChatGroups.ErrorStateSelf-managing — only renders when fetchState === 'error'.
CometChatGroups.LoadingStateSelf-managing — only renders when fetchState === 'loading'.

Props

Flat API (<CometChatGroups />)

All Root props below, plus these convenience view props:
PropTypeDescription
leadingView(group: CometChat.Group) => ReactNodeCustom leading view per item (replaces avatar).
titleView(group: CometChat.Group) => ReactNodeCustom title view per item.
subtitleView(group: CometChat.Group) => ReactNodeCustom subtitle view per item.
trailingView(group: CometChat.Group) => ReactNodeCustom trailing view per item.
itemView(group: CometChat.Group) => ReactNodeFully custom item (overrides all above).
headerViewReactNodeCustom header (replaces default).
loadingViewReactNodeCustom loading content.
errorViewReactNodeCustom error content.
emptyViewReactNodeCustom empty content.

CometChatGroups.Root

PropTypeDefaultDescription
requestBuilderCometChat.GroupsRequestBuilderlimit 30Custom request builder for fetching groups.
searchRequestBuilderCometChat.GroupsRequestBuilderCustom request builder for search queries.
searchKeywordstring''Initial search keyword.
hideGroupTypebooleanfalseWhether to hide the group type badge (public/private/password).
selectionMode'none' | 'single' | 'multiple''none'Selection mode.
activeGroupCometChat.GroupGroup to highlight as active.
options(group: CometChat.Group) => CometChatGroupOption[]Context menu options per group.
onItemClick(group: CometChat.Group) => voidCallback when a group is clicked. Used for sibling component communication.
onSelect(group: CometChat.Group, selected: boolean) => voidCallback when selection changes.
onError(error: unknown) => voidCallback when an error occurs.
onEmpty() => voidCallback when the list is empty.
showScrollbarbooleanfalseShow the native scrollbar on the list.
childrenReactNodeCustom layout. If omitted, renders default.

CometChatGroups.Header

PropTypeDefaultDescription
titlestring'Groups'Custom title text.
childrenReactNodeCustom header content (replaces default).
PropTypeDefaultDescription
placeholderstring'Search groups'Placeholder text for the search input.

CometChatGroups.List

PropTypeDefaultDescription
itemView(group: CometChat.Group) => ReactNodeCustom render function for each group item.

CometChatGroups.Item

PropTypeDefaultDescription
groupCometChat.GrouprequiredThe group to render.
isActivebooleanOverride active state.
leadingViewReactNodeCustom leading view (replaces avatar).
titleViewReactNodeCustom title view.
subtitleViewReactNodeCustom subtitle view (replaces member count).
trailingViewReactNodeCustom trailing view (replaces selection control).

CometChatGroups.EmptyState

PropTypeDefaultDescription
childrenReactNodeCustom empty state content (replaces default).

CometChatGroups.ErrorState

PropTypeDefaultDescription
childrenReactNodeCustom error state content (replaces default).

CometChatGroups.LoadingState

PropTypeDefaultDescription
childrenReactNodeCustom loading state content (replaces default shimmer).

Sibling Communication with onItemClick

The onItemClick callback enables communication between sibling components. The parent component owns the shared state and passes it down:
import { CometChatGroups } from '@cometchat/chat-uikit-react';
import { CometChatMessageList } from '@cometchat/chat-uikit-react';
import { useState } from 'react';
import { CometChat } from '@cometchat/chat-sdk-javascript';

function ChatApp() {
  const [activeGroup, setActiveGroup] = useState<CometChat.Group | null>(null);

  return (
    <div style={{ display: 'flex' }}>
      <CometChatGroups onItemClick={setActiveGroup} activeGroup={activeGroup} />

      {activeGroup && (
        <CometChatMessageList group={activeGroup} />
      )}
    </div>
  );
}

Custom Request Builder

Use requestBuilder to customize the SDK query for fetching groups:
import { CometChat } from '@cometchat/chat-sdk-javascript';

const builder = new CometChat.GroupsRequestBuilder()
  .setLimit(50)
  .joinedOnly(true);

<CometChatGroups requestBuilder={builder} />
You can also provide a separate searchRequestBuilder for search queries:
const searchBuilder = new CometChat.GroupsRequestBuilder()
  .setLimit(30)
  .setSearchKeyword('');  // keyword will be set dynamically

<CometChatGroups.Root
  requestBuilder={builder}
  searchRequestBuilder={searchBuilder}
/>

Group Types

Each group displays a type badge at the bottom-right of the avatar (unless hideGroupType is set to true):
TypeBadgeDescription
PublicNo badgeOpen group, anyone can join.
PrivateOrange circle + shield iconInvite-only group.
PasswordGreen circle + lock iconRequires password to join.
// Hide the group type badge
<CometChatGroups hideGroupType />

Selection Modes

None (default)

No selection controls are shown. Clicking a group triggers onItemClick.

Single

Radio buttons appear in the trailing view. Only one group can be selected at a time.

Multiple

Checkboxes appear in the trailing view. Multiple groups can be selected. Supports shift-click range selection.
<CometChatGroups.Root
  selectionMode="multiple"
  onSelect={(group, selected) => {
    console.log(group.getName(), selected ? 'selected' : 'deselected');
  }}
>
  <CometChatGroups.Header />
  <CometChatGroups.SearchBar />
  <CometChatGroups.List />
</CometChatGroups.Root>

Group Mutations

The context exposes mutation methods for group operations:
import { useCometChatGroupsContext } from '@cometchat/chat-uikit-react';

function GroupActions() {
  const { createGroup, joinGroup, leaveGroup, deleteGroup } = useCometChatGroupsContext();

  const handleJoin = async (guid: string) => {
    await joinGroup(guid, 'public');
  };

  const handleJoinPassword = async (guid: string, password: string) => {
    await joinGroup(guid, 'password', password);
  };

  const handleLeave = async (guid: string) => {
    await leaveGroup(guid);
  };

  const handleDelete = async (guid: string) => {
    await deleteGroup(guid);
  };

  return null;
}

Context Hook

Access the groups context from any child component inside CometChatGroups.Root:
import { useCometChatGroupsContext } from '@cometchat/chat-uikit-react';

function CustomGroupCount() {
  const { groups, fetchState } = useCometChatGroupsContext();
  if (fetchState !== 'loaded') return null;
  return <span>{groups.length} groups</span>;
}
The context provides:
PropertyTypeDescription
groupsCometChat.Group[]List of fetched groups.
fetchState'idle' | 'loading' | 'loaded' | 'error' | 'empty'Current fetch lifecycle state.
hasMorebooleanWhether more pages are available.
errorstring | nullError message (if fetchState is ‘error’).
selectedGroupIdsstring[]GUIDs of selected groups.
searchTextstringCurrent search text.
fetchNext() => Promise<void>Fetch next page of groups.
setSearchText(text: string) => voidSet search text (triggers re-fetch).
selectGroup(group: CometChat.Group) => voidSelect a group.
deselectGroup(groupId: string) => voidDeselect a group by GUID.
clearSelection() => voidClear all selections.
createGroup(group: CometChat.Group) => Promise<CometChat.Group>Create a new group.
joinGroup(guid, groupType, password?) => Promise<CometChat.Group>Join a group.
leaveGroup(guid: string) => Promise<boolean>Leave a group.
deleteGroup(guid: string) => Promise<boolean>Delete a group.

Accessibility

  • List container: role="listbox" with aria-label="Groups list"
  • Group items: role="option" with aria-selected
  • Group type badges: aria-label describing the type (e.g., “Private group”, “Password protected group”)
  • Loading state: aria-busy="true"
  • Empty/Error states: role="status"
  • Keyboard: Tab to focus, ArrowUp/ArrowDown to navigate, Enter/Space to select, Escape to clear search
  • All icon-only buttons have aria-label

CSS Customization

The component uses CSS custom properties for theming:
:root {
  --cometchat-primary-color: #6851d6;
  --cometchat-background-color-01: #ffffff;
  --cometchat-text-color-primary: #141414;
  --cometchat-text-color-secondary: #727272;
  --cometchat-success-color: #09c26f;
  --cometchat-warning-color: #ffab00;
}

Real-Time Updates

The component automatically handles:
  • Member joined — updates member count
  • Member left — updates member count; removes group if logged-in user left
  • Member banned/kicked — updates member count; removes group if logged-in user was banned/kicked
  • Scope changed — updates group in list
  • Group deleted — removes group from list
  • Connection recovery — re-fetches groups on network reconnect
  • Selection persistence — selections persist across search operations