Skip to main content
FieldValue
Package@cometchat/chat-uikit-react
FrameworkAstro (with @astrojs/react islands)
ComponentsCometChatMessageHeader, CometChatMessageList, CometChatMessageComposer
LayoutSingle chat window — no sidebar, no conversation list
PrerequisiteComplete Astro Integration Steps 1–5 first
SSRclient:only="react" directive — CometChat requires browser APIs
PatternSupport chat, embedded widgets, focused messaging
This guide builds a single chat window — no sidebar, no conversation list. Users go directly into a one-to-one or group chat. Good for support chat, embedded widgets, or any focused messaging experience. This assumes you’ve already completed Astro Integration (project created, React added, UI Kit installed).

What You’re Building

Three components stacked vertically:
  1. Chat header — displays recipient name, avatar, online status, and optional call buttons
  2. Message list — real-time chat history with scrolling
  3. Message composer — text input with media, emojis, and reactions

Step 1 — Create the React Island

Create a OneToOneChat component inside src/components/. This handles init, login, fetches the target user, and renders the chat UI.
src
components
OneToOneChat.tsx
OneToOneChat.css
OneToOneChat.tsx
Key points:
  • CometChat.getUser(UID) fetches the user object from the SDK — you need a real user object, not a manually constructed one.
  • Pass either user or group to the message components, never both.
  • The highlighted lines show where to set your credentials and target UID.

Switching Between User and Group Chat

To load a group chat instead of one-to-one, replace the getUser call with getGroup:

Step 2 — Render the Astro Page

Import the island and hydrate it client-side using client:only="react".
src/pages/index.astro
The client:only="react" directive ensures the component skips SSR entirely and only renders in the browser.

Step 3 — Run the Project

You should see the chat window load with the conversation for the UID you set.

Next Steps

Theming

Customize colors, fonts, and styles to match your brand

Components Overview

Browse all prebuilt UI components
Astro

Astro Integration

Back to the main setup guide

Core Features

Chat features included out of the box