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
- Completed the Integration Guide guide
- A running
CometChatProvidersetup with valid credentials - Familiarity with the Conversations and Message List components
Components Used
Step 1: Set up the app shell
Wrap your application inCometChatProvider 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.
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 withCometChat.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
TheCometChatGroupMembers 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.
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 withCometChat.leaveGroup() — except the owner. An owner must hand ownership to another member with CometChat.transferGroupOwnership() first; leaving before transferring rejects with an error.
Step 7: Display conversations and select a group
UseCometChatConversations 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
CombineCometChatMessageList 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 tocreateGroup 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
- Groups — browse and join existing groups
- Group Members — manage group membership with role-based actions
- Kick / Ban Members · Change Member Scope · Transfer Ownership — SDK references
- Message Header — customize the group header
- Event System — react to
ui:group/createdand other group action events - CometChatProvider — configure the root provider