Goal
By the end of this guide you will have a chat interface where users can initiate new one-on-one conversations by selecting from a user list, or start group chats by selecting from available groups — then immediately begin messaging.Prerequisites
- Completed the Integration Guide guide
- A running
CometChatProvidersetup with valid credentials - Familiarity with CometChatUsers and CometChatGroups components
Components Used
| Component / API | Purpose |
|---|---|
CometChatUsers | Lists available users for 1:1 chat selection |
CometChatGroups | Lists available groups for group chat selection |
CometChatConversations | Shows existing conversations |
CometChatMessageHeader | Displays selected user/group info |
CometChatMessageList | Renders conversation messages |
CometChatMessageComposer | Text input for the conversation |
CometChat.joinGroup() | SDK method to join a group |
Step 1: Set up the app shell
Wrap your application inCometChatProvider and create a layout that will hold the conversation area and a trigger for starting new chats.
App.tsx
Step 2: Add a “New Chat” trigger
Create a button that opens a selection panel. Use component state to toggle between the conversations view and the user/group selection view.NewChatApp.tsx
Step 3: Build the user/group selector
UseCometChatUsers and CometChatGroups to let the user pick a chat target. Add tabs to switch between users and groups.
UserGroupSelector.tsx
Step 4: Start a one-on-one conversation
When a user is selected from the list, pass theCometChat.User object to CometChatMessageList and CometChatMessageComposer. The SDK automatically creates the conversation when the first message is sent — no explicit creation step is needed.
ChatView.tsx
Step 5: Start a group conversation
For groups, the flow is the same — select a group fromCometChatGroups and pass the CometChat.Group object to the message components. If the user hasn’t joined the group yet, you can call CometChat.joinGroup() before opening the chat.
Step 6: Send the first message programmatically (optional)
If you want to send an initial message when starting a new chat (for example, an icebreaker), use the SDK directly after selecting a user.Complete Example
NewChatApp.tsx
Next Steps
- CometChatUsers — customize the user list appearance and filtering
- CometChatGroups — browse and manage groups
- Conversations — display existing conversations
- Group Chat Setup — create and configure group conversations