Skip to main content

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

Components Used

Step 1: Set up the app shell

Wrap your application in CometChatProvider 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

Use CometChatUsers 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 the CometChat.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 from CometChatGroups 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