Skip to main content
Browse and select groups with search, member counts, and group type indicators.

When to use this

  • You need a searchable list of groups.
  • You want a group picker to start group chats.
  • You need to filter groups by tags or type.

Prerequisites

  • CometChat React UI Kit v6 installed: @cometchat/chat-uikit-react.
  • CometChatUIKit.init() and CometChatUIKit.login() complete before rendering.

Quick start

  1. Add the component to your UI.
import React from "react";
import { CometChatGroups } from "@cometchat/chat-uikit-react";

export default function GroupsDemo() {
  return <CometChatGroups />;
}
What this does: Renders the minimal version of the component.
  1. Verify the component renders after init() and login().

Core concepts

  • groupsRequestBuilder controls filtering and paging.
  • selectionMode enables multi-select workflows.
  • hideGroupType toggles the group type icon.

Implementation

  • Package: @cometchat/chat-uikit-react
  • Import: import { CometChatGroups } from "@cometchat/chat-uikit-react";
  • Minimal JSX: <CometChatGroups />
  • Required setup: CometChatUIKit.init(UIKitSettings) then CometChatUIKit.login("UID")
  • Key props: onItemClick: (group: CometChat.Group) => void, selectionMode: SelectionMode, groupsRequestBuilder: CometChat.GroupsRequestBuilder, hideSearch: boolean, hideGroupType: boolean
  • CSS class: .cometchat-groups

Overview

What you’re changing: Overview. Where to change it: Component props or CSS as shown below. Default behavior: UI Kit defaults. Override: Use the examples in this section. Verify: The UI reflects the change shown below. The Groups is a Component, showcasing an accessible list of all available groups. It provides an integral search functionality, allowing you to locate any specific groups swiftly and easily. For each group listed, the group name is displayed by default, in conjunction with the group icon when available. Additionally, it provides a useful feature by displaying the number of members in each group as a subtitle, offering valuable context about group size and activity level.
Before using this component: Ensure CometChatUIKit.init(UIKitSettings) has completed and the user is logged in via CometChatUIKit.login("UID"). See React.js Integration.
The Groups component is composed of the following BaseComponents:
ComponentsDescription
CometChatListA reusable container component having title, search box, customisable background and a list view.
CometChatListItemA component that renders data obtained from a Group object on a Tile having a title, subtitle, leading and trailing view.

Usage

What you’re changing: Usage. Where to change it: Component props or CSS as shown below. Default behavior: UI Kit defaults. Override: Use the examples in this section. Verify: The UI reflects the change shown below.

Integration

The following code snippet illustrates how you can directly incorporate the Groups component into your Application.
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  return <CometChatGroups />;
};

export default GroupsDemo;
What this does: Shows the code for this step.

Actions

Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.
1. onSelect
The onSelect action is activated when you select the done icon while in selection mode. This returns the group object along with the boolean flag selected to indicate if the group was selected or unselected. This action does not come with any predefined behavior. However, you have the flexibility to override this event and tailor it to suit your needs using the following code snippet.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups, SelectionMode } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  function handleOnSelect(group: CometChat.Group, selected: boolean): void {
    console.log(group);
    //your custom onSelect actions
  }
  return (
    <CometChatGroups
      selectionMode={SelectionMode.multiple}
      onSelect={handleOnSelect}
    />
  );
};

export default GroupsDemo;
What this does: Shows the code for this step.
2. onItemClick
The onItemClick event is activated when you click on the Group List item. This action does not come with any predefined behavior. However, you have the flexibility to override this event and tailor it to suit your needs using the following code snippet.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  function handleOnItemClick(group: CometChat.Group): void {
    console.log(group, "your custom on item click action");
  }
  return <CometChatGroups onItemClick={handleOnItemClick} />;
};

export default GroupsDemo;
What this does: Shows the code for this step.
3. onError
This action doesn’t change the behavior of the component but rather listens for any errors that occur in the Groups component.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  const handleOnError = (error: CometChat.CometChatException) => {
    console.log("Your custom on error actions");
  };
  return <CometChatGroups onError={handleOnError} />;
};

export default GroupsDemo;
What this does: Shows the code for this step.

Filters

Filters allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using RequestBuilders of Chat SDK.
1. GroupsRequestBuilder
The GroupsRequestBuilder enables you to filter and customize the group list based on available parameters in GroupsRequestBuilder. This feature allows you to create more specific and targeted queries when fetching groups. The following are the parameters available in GroupsRequestBuilder
MethodsTypeDescription
setLimitnumbersets the number groups that can be fetched in a single request, suitable for pagination
setSearchKeywordStringused for fetching groups matching the passed string
joinedOnlybooleanto fetch only joined groups.
setTagsArray<String>used for fetching groups containing the passed tags
withTagsbooleanused to fetch tags data along with the list of groups
Example In the example below, we are applying a filter to the Group List based on only joined groups and setting the limit to two.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  return (
    <CometChatGroups
      groupsRequestBuilder={new CometChat.GroupsRequestBuilder()
        .setLimit(2)
        .joinedOnly(true)}
    />
  );
};

export default GroupsDemo;
What this does: Shows the code for this step.
2. SearchRequestBuilder
The SearchRequestBuilder uses GroupsRequestBuilder enables you to filter and customize the search list based on available parameters in GroupsRequestBuilder. This feature allows you to keep uniformity between the displayed Groups List and searched Group List. Example
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  return (
    <CometChatGroups
      searchRequestBuilder={new CometChat.GroupsRequestBuilder()
        .setLimit(2)
        .setSearchKeyword("your keyword")}
    />
  );
};

export default GroupsDemo;
What this does: Shows the code for this step.

Events

Events are emitted by a Component. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed. To handle events supported by Groups you have to add corresponding listeners by using CometChatGroupEvents The Groups component does not produce any events directly.

Customization

What you’re changing: Customization. Where to change it: Component props or CSS as shown below. Default behavior: UI Kit defaults. Override: Use the examples in this section. Verify: The UI reflects the change shown below. To fit your app’s design requirements, you can customize the appearance of the Groups component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.

Style

Using CSS you can customize the look and feel of the component in your app like the color, size, shape, and fonts. Example
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  return <CometChatGroups />;
};

export default GroupsDemo;
What this does: Shows the code for this step.

Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements.
import { CometChatGroups, TitleAlignment } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  return (
    <CometChatGroups
      title="Your Custom Title"
      titleAlignment={TitleAlignment.center}
      hideSearch={true}
    />
  );
};

export default GroupsDemo;
What this does: Shows the code for this step.
Below is a list of customizations along with corresponding code snippets:
PropertyDescriptionCode
Hide SearchHides the default search bar.hideSearch={true}
Hide ErrorHides the default and custom error view passed in errorView prop.hideError={true}
Hide Group TypeHides the group type icon.hideGroupType={true}
Active GroupThe group to highlight in the list.activeGroup={chatGroup}
Selection ModeSelection mode to use for the default trailing view.selectionMode={SelectionMode.multiple}
Show ScrollbarControls the visibility of the scrollbar in the list.showScrollbar={true}
Loading ViewA custom view to display during the loading state.loadingView={<>Custom Loading View</>}
Empty ViewCustom view for the empty state of the component.emptyView={<>Custom Empty View</>}
Error ViewA custom view to display when an error occurs.errorView={<>Custom Error View</>}

Advanced

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.
ItemView
A custom view to render for each group in the fetched list. Shown below is the default chat interface.
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  const getItemView = (group: CometChat.Group) => {
    return (
      <div className="group-list-item">
        <div className="group-list-item__title-wrapper">
          <div className="group-list-item__title">{group.getName()}</div>
          <div className="group-list-item__tail">JOIN</div>
        </div>
        <div className="group-list-item__subtitle">
          {group.getMembersCount()} Members • {group.getDescription()}
        </div>
      </div>
    );
  };

  return <CometChatGroups itemView={getItemView} />;
};

export default GroupsDemo;
What this does: Shows the code for this step.

TitleView
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";

// Custom title view component
const customTitleView = (group: CometChat.Group) => {
   return <div className={`groups__title-view groups__title-view-${group.getType()}`}>
      <span className="groups__title-view-name">{group.getName()}</span>
      <span className="groups__title-view-type"><img src={"ICON_HERE"}/>{group.getType()}</span>
  </div>;
}

<CometChatGroups user={userObj} titleView={customTitleView} />;
What this does: Shows the code for this step.

SubtitleView
Custom subtitle view to be rendered for each group in the fetched list. Shown below is the default chat interface.
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  const getSubtitleView = (group: CometChat.Group): JSX.Element => {
    if (!(group instanceof CometChat.Group)) {
      return <></>;
    }

    return (
      <div className="group-subtitle">
        {group.getMembersCount()} Members • {group.getDescription()}
      </div>
    );
  };

  return <CometChatGroups subtitleView={getSubtitleView} />;
};

export default GroupsDemo;
What this does: Shows the code for this step.

LeadingView
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroups,CometChatAvatar } from "@cometchat/chat-uikit-react";

// Custom leading view component
 const customLeadingView = (group: CometChat.Group) => {
        return <>
            {group.getHasJoined() ? <div className="groups__leading-view groups__leading-view-joined">
                <CometChatAvatar
                    image={group?.getIcon()}
                    name={group?.getName()}
                />
                {/* Icon here */}
                <span className="groups__leading-view-info"> Joined</span>


            </div> : <div className="groups__leading-view">
                <CometChatAvatar
                    image={group?.getIcon()}
                    name={group?.getName()}
                />
                {/* Icon here */}
                <span className="groups__leading-view-info"> Join</span>


            </div>}</>;
    }

<CometChatGroups  leadingView={customLeadingView} />;
What this does: Shows the code for this step.

TrailingView
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
  CometChatGroups,
} from "@cometchat/chat-uikit-react";

// Custom trailing view component
const customTrailingButtonView = (group:CometChat.Group) =>  {
return <div className="groups__trailing-view">
 {group.getHasJoined() ? "JOINED" : "+ JOIN"}
</div>
}

<CometChatGroups  trailingView={customTrailingButtonView} />;
What this does: Shows the code for this step.

Header View
A custom component to render in the top-right corner of the groups list. The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import { CometChatGroups } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  const getHeaderView = () => {
    return <div className="group-header-view" />;
  };

  return <CometChatGroups headerView={getHeaderView()} />;
};

export default GroupsDemo;
What this does: Shows the code for this step.

Options
You can set the Custom options to the Groups component. The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import { CometChatGroups, CometChatOption } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupsDemo = () => {
  const getOptions = (group: CometChat.Group): CometChatOption[] => {
    return [
      new CometChatOption({
        id: "delete",
        title: "delete",
        onClick: () => {
          console.log("Custom option clicked for group:", group);
        },
      }),
    ];
  };

  return <CometChatGroups options={getOptions} />;
};

export default GroupsDemo;
What this does: Shows the code for this step.

Component API Pattern

What you’re changing: Component API Pattern. Where to change it: Component props or CSS as shown below. Default behavior: UI Kit defaults. Override: Use the examples in this section. Verify: The UI reflects the change shown below.
Customization TypeProp PatternExample
Callback actionson<Event>={(param) => {}}onItemClick={(group) => {}}
Data filteringgroupsRequestBuilder={new CometChat.GroupsRequestBuilder()}groupsRequestBuilder={builder}
Toggle featureshide<Feature>={true|false}hideSearch={true}
Custom rendering<slot>View={(<params>) => JSX}itemView={(group) => <div>...</div>}
CSS overridesTarget .cometchat-groups class in global CSS.cometchat-groups { ... }
SymptomCauseFix
Component doesn’t renderCometChatUIKit.init() not called or not awaitedEnsure init completes before rendering. See Methods
Component renders but shows no dataUser not logged inCall CometChatUIKit.login("UID") after init
Callback not firingWrong prop name or signatureCheck the Actions section for exact prop name and parameter types
Custom view not appearingReturning null or undefined from view propEnsure view function returns valid JSX
SSR hydration errorComponent uses browser APIs on serverWrap in useEffect or dynamic import with ssr: false. See Next.js Integration

Customization matrix

What you want to changeWhereProperty/APIExample
Handle item clickCometChatGroupsonItemClickonItemClick={(g) => setActive(g)}
Enable multi-selectCometChatGroupsselectionModeselectionMode={SelectionMode.multiple}
Filter groupsCometChatGroupsgroupsRequestBuildernew CometChat.GroupsRequestBuilder().setLimit(10)
Hide group typeCometChatGroupshideGroupTypehideGroupType={true}

Common pitfalls and fixes

SymptomCauseFix
Component does not renderInit/login not completeCall CometChatUIKit.init() and login() first
List is emptyFilters too strictRelax groupsRequestBuilder filters
Group type icon missinghideGroupType enabledSet hideGroupType={false}
Callbacks not firingWrong prop nameUse onItemClick or onSelect
Styles not applyingCSS Modules usedUse global CSS with .cometchat-groups

FAQ

Can I show only joined groups? Yes. Use GroupsRequestBuilder filters for membership. How do I hide the group type icon? Set hideGroupType={true}.

Next steps