Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-react-uikit-v7.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

FieldValue
ClassCometChatUIKit
Package@cometchat/chat-uikit-react
UsageStatic methods — no instantiation needed
NoteMost users don’t need these directly — CometChatProvider handles init and login automatically

Overview

CometChatUIKit is a static class that provides imperative methods for SDK initialization, authentication, and message sending. Most users won’t need these directly — CometChatProvider handles init and login automatically. These methods are useful for:

Initialization

CometChatUIKit.init(settings)

Initialize the CometChat SDK and UIKit.
import { CometChatUIKit, UIKitSettingsBuilder } from "@cometchat/chat-uikit-react";

const settings = new UIKitSettingsBuilder()
  .setAppId("APP_ID")
  .setRegion("us")
  .setAuthKey("AUTH_KEY")
  .subscribePresenceForAllUsers()
  .build();

const user = await CometChatUIKit.init(settings);
// user is non-null if an existing session was found
ParameterTypeDescription
settingsUIKitSettingsBuilt via UIKitSettingsBuilder
Returns: Promise<CometChat.User | null> — the logged-in user if a session exists, otherwise null. What it does:
  1. Initializes the CometChat SDK with app settings
  2. Sets source metadata for analytics
  3. Creates the plugin registry (default + user plugins)
  4. Initializes the localization singleton
  5. Resumes existing session (if any)
  6. Initializes Calls SDK (if enabled)

Authentication

CometChatUIKit.login(uid)

Log in a user by UID. Requires authKey in UIKitSettings.
const user = await CometChatUIKit.login("superhero1");
ParameterTypeDescription
uidstringThe user’s UID
Returns: Promise<CometChat.User>

CometChatUIKit.loginWithAuthToken(authToken)

Log in with a server-generated auth token. Preferred for production.
const user = await CometChatUIKit.loginWithAuthToken(token);
ParameterTypeDescription
authTokenstringServer-generated auth token
Returns: Promise<CometChat.User>

CometChatUIKit.logout()

Log out the current user.
await CometChatUIKit.logout();
Returns: Promise<void>

State Getters

CometChatUIKit.getLoggedInUser()

Get the currently logged-in user (synchronous).
const user = CometChatUIKit.getLoggedInUser();
Returns: CometChat.User | null

CometChatUIKit.isInitialized()

Check if the SDK has been initialized.
if (CometChatUIKit.isInitialized()) { ... }
Returns: boolean

CometChatUIKit.isCallingReady()

Check if the Calls SDK is ready. Returns: boolean

CometChatUIKit.getPluginRegistry()

Get the plugin registry instance. Returns: CometChatPluginRegistry | null

CometChatUIKit.getSettings()

Get the UIKitSettings used during initialization. Returns: UIKitSettings | null

CometChatUIKit.getConversationUpdateSettings()

Get conversation update settings fetched from the dashboard. Returns: CometChat.ConversationUpdateSettings | null

Message Sending

These methods are low-level utilities. They send messages via the SDK but do not publish ui:message/sent events. This means:
  • The message won’t appear in CometChatMessageList automatically
  • The CometChatConversations list won’t update
For messages to appear in the UI, use the CometChatMessageComposer component, or manually publish the event after sending:
const publish = usePublishEvent();
const msg = await CometChatUIKit.sendTextMessage(message);
publish({ type: "ui:message/sent", message: msg, status: CometChatMessageStatus.success });

CometChatUIKit.sendTextMessage(message)

Send a text message. Sets muid and sentAt if not already set.
const textMessage = new CometChat.TextMessage("receiverUid", "Hello!", "user");
const sent = await CometChatUIKit.sendTextMessage(textMessage);
Returns: Promise<CometChat.BaseMessage>

CometChatUIKit.sendMediaMessage(message)

Send a media message (image, video, audio, file).
const mediaMessage = new CometChat.MediaMessage("receiverUid", file, "image", "user");
const sent = await CometChatUIKit.sendMediaMessage(mediaMessage);
Returns: Promise<CometChat.BaseMessage>

CometChatUIKit.sendCustomMessage(message)

Send a custom message (polls, location, etc.).
const customMessage = new CometChat.CustomMessage("receiverUid", "user", "location", { latitude: 37.7749, longitude: -122.4194 });
const sent = await CometChatUIKit.sendCustomMessage(customMessage);
Returns: Promise<CometChat.BaseMessage>