Skip to main content
This guide builds a two-panel chat layout — conversation list on the left, messages on the right. Users click a conversation to open it. This assumes you’ve already completed Astro Integration (project created, UI Kit installed, init + login working).

What You’re Building

Three sections working together:
  1. Sidebar (conversation list) — shows all active conversations (users and groups)
  2. Message view — displays chat messages for the selected conversation in real time
  3. Message composer — text input with support for media, emojis, and reactions

Full Code

Create a React island component with the chat UI, then render it in an Astro page with client:only="react".
src/components/ConversationChat.tsx
src/pages/chat.astro

How It Works

  1. client:only="react" tells Astro to skip server-rendering and hydrate the component entirely on the client. This is required because CometChat uses browser APIs.
  2. React island — the CometChat UI lives in a self-contained React component. Astro handles the page shell, React handles the interactive chat.
  3. CometChatProvider wraps the entire tree — it supplies theme, locale, and event context to all CometChat components.
  4. CometChatConversations renders the sidebar list. When a user clicks a conversation, onItemClick fires with the Conversation object.
  5. handleConversationClick extracts the User or Group from the conversation and stores it in state.
  6. Message components (MessageHeader, MessageList, MessageComposer) receive either user or group as a prop — never both at the same time.

Run

Open http://localhost:4321/chat. You should see the conversation list on the left. Click any conversation to load messages on the right.

Next Steps

One-to-One / Group Chat

Single chat window without a sidebar

Tab-Based Chat

Tabbed navigation with Chats, Calls, Users

Components Overview

Browse all prebuilt UI components

Theming

Customize colors, fonts, and styles