Skip to main content

Goal

By the end of this guide you will have a working group chat where users can create a group of any type (public, password-protected, or private), add and remove members with role-based permissions, join or leave a group, transfer ownership, and exchange messages in real time using the CometChat components.

Prerequisites

Components Used

Step 1: Set up the app shell

Wrap your application in CometChatProvider and create a layout with a sidebar for conversations and a main area for messages.
App.tsx

Step 2: Create a group

A group has one of three types, and the type decides how other users can get in. Choose the right one up front — it changes both the create call and how (or whether) users can join. Create a group with CometChat.createGroup(). The CometChat.Group constructor takes a fourth password argument — it is required for password-protected groups and ignored for the other two types.
For a password-protected group you must pass the password as the fourth argument. new CometChat.Group(guid, name, CometChat.GROUP_TYPE.PASSWORD) with no password creates a group nobody can join.
When a group is created through the UI Kit’s built-in flow, it publishes the ui:group/created event on the Event System. Subscribe with useCometChatEvents if other components need to react to new groups being created.

Step 3: Add members

The creator becomes the group owner (with admin privileges). Add members with CometChat.addMembersToGroup() — each member is a CometChat.GroupMember with a UID and a scope (ADMIN, MODERATOR, or PARTICIPANT).
Adding members requires an admin or moderator scope in the target group — a participant cannot add members. Assign PARTICIPANT by default and only grant ADMIN/MODERATOR when a member needs management rights. For private groups this is the only way in — there is no join. To let a user pick who to add, render CometChatUsers in selection mode and pass the chosen UIDs to addMembersToGroup().

Step 4: Join a group

How a user joins depends on the group type:
Only public and password-protected groups can be joined. A private group is add-only — calling joinGroup() on it fails; add the user via Step 3 instead. The built-in CometChatGroups list surfaces a password prompt for password-protected groups automatically.

Step 5: Manage members — remove, ban, and change roles

The CometChatGroupMembers component renders the member list with built-in kick, ban, and change-scope actions. It shows or hides those actions based on the logged-in user’s role, so you don’t have to gate them yourself.
Group actions are scope-based — a participant can never perform them: If you build your own controls instead of using the component’s menu, the SDK methods are:
Calling these as a participant — or a moderator acting on an admin — rejects with a permission error. Let the acting user’s scope drive which controls you render. The component already does this for its default kick/ban/scope menu.

Step 6: Leave a group and transfer ownership

Any member can leave with CometChat.leaveGroup()except the owner. An owner must hand ownership to another member with CometChat.transferGroupOwnership() first; leaving before transferring rejects with an error.
Wiring “Leave Group” straight to leaveGroup() throws for the owner. Detect the owner (group.getOwner() === loggedInUser.getUid()), show an ownership-transfer step (a member picker — CometChatGroupMembers in selection mode works well), call transferGroupOwnership(), and only then leaveGroup(). See the SDK Transfer Group Ownership and Leave Group references.

Step 7: Display conversations and select a group

Use CometChatConversations to show the user’s conversations. When a group conversation is selected, pass the group object to the message components.

Step 8: Render the group message view

Combine CometChatMessageList and CometChatMessageComposer to display messages and allow sending within the selected group.

Step 9: Add a create-group form

Provide a UI for users to create groups on the fly. Show a password field only when the selected type is password-protected, and pass it through to createGroup from Step 2.

Complete Example

The “New Group” button lives in the conversation list’s headerView slot — not in a separate <div> stacked above the list — so the list header stays intact and the layout doesn’t shift. Because headerView replaces the entire default header, re-render the default title (“Chats”) alongside the button.
GroupChat.tsx

Next Steps