Skip to main content

Goal

By the end of this guide you will have a working group chat interface where users can create a new group, add members, and exchange messages in real time using the CometChat compound 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 new group

Use CometChat.createGroup() to programmatically create a group. You need a unique GUID, a name, and a group type (public, private, or password-protected).

Step 3: Add members to the group

After creating a group, add members using CometChat.addMembersToGroup(). Each member needs a UID and a scope (admin, moderator, or participant).

Step 4: Join an existing group

For public groups, users can join without an invite using CometChat.joinGroup().

Step 5: 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 6: Render the group message view

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

Step 7: Add a create-group form

Provide a simple UI for users to create groups on the fly. Wire it to the createGroup function from Step 2.

Complete Example

GroupChat.tsx

Next Steps