Documentation Index Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
AI Integration Quick Reference
Field Value Package @cometchat/chat-uikit-reactFramework Next.js Components CometChatConversations, CometChatMessageHeader, CometChatMessageList, CometChatMessageComposerLayout Two-panel — conversation list (left) + message view (right) Prerequisite Complete Next.js Integration Steps 1–5 first SSR Dynamic import with ssr: false — CometChat requires browser APIs Pattern WhatsApp Web, Slack, Microsoft Teams
This guide builds a two-panel chat layout — conversation list on the left, messages on the right. Users tap a conversation to open it.
This assumes you’ve already completed Next.js Integration (project created, UI Kit installed, CSS imported).
Fork the sandbox, insert your CometChat credentials (App ID, Region, Auth Key), and preview the UI in real time.
What You’re Building
Three sections working together:
Sidebar (conversation list) — shows all active conversations (users and groups)
Message view — displays chat messages for the selected conversation in real time
Message composer — text input with support for media, emojis, and reactions
import { useEffect , useState } from "react" ;
import { Conversation , Group , User , CometChat } from "@cometchat/chat-sdk-javascript" ;
import { CometChatConversations , CometChatUIKitLoginListener } from "@cometchat/chat-uikit-react" ;
import "./CometChatSelector.css" ;
interface SelectorProps {
onSelectorItemClicked ?: ( input : User | Group | Conversation , type : string ) => void ;
}
export const CometChatSelector = ( props : SelectorProps ) => {
const { onSelectorItemClicked = () => {} } = props ;
const [ loggedInUser , setLoggedInUser ] = useState < CometChat . User | null >();
const [ activeItem , setActiveItem ] = useState <
CometChat . Conversation | CometChat . User | CometChat . Group | undefined
> ();
useEffect (() => {
const user = CometChatUIKitLoginListener . getLoggedInUser ();
setLoggedInUser ( user );
}, []);
return (
<>
{ loggedInUser && (
< CometChatConversations
activeConversation = {
activeItem instanceof CometChat . Conversation ? activeItem : undefined
}
onItemClick = { ( e ) => {
setActiveItem ( e );
onSelectorItemClicked ( e , "updateSelectedItem" );
} }
/>
) }
</>
);
};
.selector-wrapper .cometchat-conversations .cometchat-list__header-menu .cometchat-button__icon {
background : var ( --cometchat-icon-color-primary );
}
.cometchat-conversations .cometchat-list__header-menu .cometchat-button__icon:hover {
background : var ( --cometchat-icon-color-highlight );
}
.cometchat-list__header-search-bar {
border-right : none ;
}
.cometchat .cometchat-menu-list__sub-menu-list-item {
text-align : left ;
}
.cometchat .cometchat-conversations .cometchat-menu-list__sub-menu-list {
width : 212 px ;
top : 40 px !important ;
left : 172 px !important ;
}
#logged-in-user {
border-bottom : 2 px solid var ( --cometchat-border-color-default , #E8E8E8 );
}
#logged-in-user .cometchat-menu-list__sub-menu-item-title ,
#logged-in-user .cometchat-menu-list__sub-menu-list-item {
cursor : default ;
}
.cometchat-menu-list__sub-menu-list-item-icon-log-out {
background-color : var ( --cometchat-error-color , #F44649 );
}
.cometchat-menu-list__sub-menu-item-title-log-out {
color : var ( --cometchat-error-color , #F44649 );
}
.chat-menu .cometchat .cometchat-menu-list__sub-menu-item-title {
cursor : pointer ;
}
.chat-menu .cometchat .cometchat-menu-list__sub-menu {
box-shadow : none ;
}
.chat-menu .cometchat .cometchat-menu-list__sub-menu-icon {
background-color : var ( --cometchat-icon-color-primary , #141414 );
width : 24 px ;
height : 24 px ;
}
Step 2 — Create the CometChatNoSSR Component
This component handles init, login, and renders the full chat experience. It runs client-side only.
import React , { useEffect , useState } from "react" ;
import {
CometChatMessageComposer ,
CometChatMessageHeader ,
CometChatMessageList ,
CometChatUIKit ,
UIKitSettingsBuilder ,
} from "@cometchat/chat-uikit-react" ;
import { CometChat } from "@cometchat/chat-sdk-javascript" ;
import { CometChatSelector } from "../CometChatSelector/CometChatSelector" ;
import "./CometChatNoSSR.css" ;
// Replace with your actual credentials
const COMETCHAT_CONSTANTS = {
APP_ID: "" , // Replace with your App ID
REGION: "" , // Replace with your Region
AUTH_KEY: "" , // Replace with your Auth Key (dev only)
};
const UID = "cometchat-uid-1" ; // Replace with your actual UID
const CometChatNoSSR : React . FC = () => {
const [ user , setUser ] = useState < CometChat . User | undefined >( undefined );
const [ selectedUser , setSelectedUser ] = useState < CometChat . User | undefined >( undefined );
const [ selectedGroup , setSelectedGroup ] = useState < CometChat . Group | undefined >( undefined );
useEffect (() => {
const UIKitSettings = new UIKitSettingsBuilder ()
. setAppId ( COMETCHAT_CONSTANTS . APP_ID )
. setRegion ( COMETCHAT_CONSTANTS . REGION )
. setAuthKey ( COMETCHAT_CONSTANTS . AUTH_KEY )
. subscribePresenceForAllUsers ()
. build ();
CometChatUIKit . init ( UIKitSettings )
?. then (() => {
console . log ( "Initialization completed successfully" );
CometChatUIKit . getLoggedinUser (). then (( loggedInUser ) => {
if ( ! loggedInUser ) {
CometChatUIKit . login ( UID )
. then (( user ) => {
console . log ( "Login Successful" , { user });
setUser ( user );
})
. catch (( error ) => console . error ( "Login failed" , error ));
} else {
console . log ( "Already logged-in" , { loggedInUser });
setUser ( loggedInUser );
}
});
})
. catch (( error ) => console . error ( "Initialization failed" , error ));
}, []);
return user ? (
< div className = "conversations-with-messages" >
< div className = "conversations-wrapper" >
< CometChatSelector
onSelectorItemClicked = { ( activeItem ) => {
let item = activeItem ;
if ( activeItem instanceof CometChat . Conversation ) {
item = activeItem . getConversationWith ();
}
if ( item instanceof CometChat . User ) {
setSelectedUser ( item as CometChat . User );
setSelectedGroup ( undefined );
} else if ( item instanceof CometChat . Group ) {
setSelectedUser ( undefined );
setSelectedGroup ( item as CometChat . Group );
} else {
setSelectedUser ( undefined );
setSelectedGroup ( undefined );
}
} }
/>
</ div >
{ selectedUser || selectedGroup ? (
< div className = "messages-wrapper" >
< CometChatMessageHeader user = { selectedUser } group = { selectedGroup } />
< CometChatMessageList user = { selectedUser } group = { selectedGroup } />
< CometChatMessageComposer user = { selectedUser } group = { selectedGroup } />
</ div >
) : (
< div className = "empty-conversation" > Select a conversation to start chatting </ div >
) }
</ div >
) : undefined ;
};
export default CometChatNoSSR ;
.conversations-with-messages {
display : flex ;
height : 100 % ;
width : 100 % ;
}
.conversations-wrapper {
height : 100 % ;
width : 480 px ;
overflow : hidden ;
display : flex ;
flex-direction : column ;
height : inherit ;
}
.conversations-wrapper > .cometchat {
overflow : hidden ;
}
.messages-wrapper {
width : calc ( 100 % - 480 px );
height : 100 % ;
display : flex ;
flex-direction : column ;
}
.empty-conversation {
height : 100 % ;
width : 100 % ;
display : flex ;
justify-content : center ;
align-items : center ;
background : white ;
color : var ( --cometchat-text-color-secondary , #727272 );
font : var ( --cometchat-font-body-regular , 400 14 px Roboto);
}
.cometchat .cometchat-message-composer {
border-radius : 0 px ;
}
Step 3 — Disable SSR in Your Page
Dynamically import CometChatNoSSR with ssr: false so it only loads client-side.
import dynamic from "next/dynamic" ;
import "@cometchat/chat-uikit-react/css-variables.css" ;
const CometChatComponent = dynamic (
() => import ( "../CometChatNoSSR/CometChatNoSSR" ),
{ ssr: false }
);
export default function Home () {
return < CometChatComponent /> ;
}
CometChat depends on browser APIs (window, WebSocket, document). Setting ssr: false ensures the component only renders on the client, avoiding hydration errors.
Step 4 — Run the Project
You should see the conversation list on the left. Tap any conversation to load messages on the right.
Next Steps
Theming Customize colors, fonts, and styles to match your brand
Components Overview Browse all prebuilt UI components
Next.js Integration Back to the main setup guide
Core Features Chat features included out of the box