AI Agent Component Spec
AI Agent Component Spec
- Package:
@cometchat/chat-uikit-react - Framework: Next.js
- Key components:
CometChatMessageHeader+CometChatMessageList+CometChatMessageComposer - Required setup:
CometChatUIKit.init(UIKitSettings)thenCometChatUIKit.login("UID") - Parent guide: Next.js Integration
Tip: You can fork the sandbox, insert your CometChat credentials (App ID, Region, Auth Key.) in the code, and immediately preview how the UI and messages respond in real time.
User Interface Preview

Key Components
- Chat Header – Displays recipient details and optional call/video call buttons.
- Message View – Shows real-time chat history.
- Message Input Box – Enables users to send messages, media, and reactions.
Step-by-Step Guide
Step 1: Implement the Chat Header
- Display profile picture, name, and online status.
- Add voice and video call buttons (optional).
Step 2: Build the Message View
- Load chat history and real-time messages.
- Ensure smooth scrolling and timestamp visibility.
Step 3: Add the Message Composer
- Include a text input field.
- Support media uploads, file attachments, emojis, and reactions.
Implementation
Now we will create theCometChatNoSSR.tsx & CometChatNoSSR.css files. Here, we will initialize the CometChat UI Kit, log in a user, and build the messaging experience using CometChatMessageHeader, CometChatMessageList, and CometChatMessageComposer components.
- TypeScript
- CSS
CometChatNoSSR.tsx
Fetching a User (One-on-One Chat)
Fetching a Group (Group Chat)
Step 4: Disabling SSR for CometChatNoSSR.tsx in Next.js
In this update, we will disable Server-Side Rendering (SSR) for CometChatNoSSR.tsx while keeping the rest of the application’s SSR functionality intact. This ensures that the CometChat UI Kit components load only on the client-side, preventing SSR-related issues.
Disabling SSR in index.tsx
Modify your index.tsx file to dynamically import the CometChatNoSSR.tsx component with { ssr: false }.
index.tsx
Why disable SSR?
- The CometChat UI Kit depends on browser APIs (window, document, WebSockets).
- Next.js pre-renders components on the server, which can cause errors with browser-specific features.
- By setting
{ ssr: false }, we ensure that CometChatNoSSR.tsx only loads on the client.
Step 5: Update Global CSS
Next, add the following styles to global.css to ensure CometChat UI Kit is properly styled.global.css
Step 6: Run the project
- npm
- pnpm
- yarn
Common Failure Modes
Common Failure Modes
Common Failure Modes
| Symptom | Cause | Fix |
|---|---|---|
| Component doesn’t render | CometChatUIKit.init() not called or not awaited | Ensure init completes before rendering. See Methods |
| Component renders but shows no data | User not logged in | Call CometChatUIKit.login("UID") after init |
| CSS/theme not applied | Missing CSS import | Add @import url("@cometchat/chat-uikit-react/css-variables.css"); in your CSS |
| Blank screen after login | Component mounted before init/login completes | Use state to conditionally render after login resolves |
| Messages not loading | Invalid user/group object passed | Ensure you fetch the user/group via SDK before passing to components |
Next Steps
Advanced Customizations
Personalize the chat UI to align with your brand.
Components Overview
Explore all available prebuilt UI components.
Next.js Integration
Return to the Next.js setup guide.
Core Features
Learn about messaging, real-time updates, and more.