Skip to main content
FieldValue
Package@cometchat/chat-uikit-react
Importimport { CometChatUIKit } from "@cometchat/chat-uikit-react";
InitCometChatUIKit.init(UIKitSettings)
Login (dev)CometChatUIKit.login("UID")
Login (prod)CometChatUIKit.loginWithAuthToken("AUTH_TOKEN")
Other methodsCometChatUIKit.logout(), CometChatUIKit.getLoggedinUser(), CometChatUIKit.createUser(user), CometChatUIKit.updateUser(user)
Send messagesCometChatUIKit.sendTextMessage(), CometChatUIKit.sendMediaMessage(), CometChatUIKit.sendCustomMessage()
NoteUse these wrapper methods instead of raw SDK calls — they manage internal UI Kit eventing
The UI Kit wraps the Chat SDK methods to manage internal eventing and keep UI components synchronized. Use these wrapper methods instead of raw SDK calls.
CometChatUIKit.init(UIKitSettings) must be called before rendering any UI Kit components or calling any SDK methods. Initialization must complete before login.
Auth Key is for development/testing only. In production, generate Auth Tokens on the server using the REST API and pass them to the client via loginWithAuthToken(). Never expose Auth Keys in production client code.

Methods

All methods are accessed via the CometChatUIKit class.

Init

Initializes the CometChat JavaScript SDK. Must be called on app startup before any other UI Kit method.
Replace APP_ID, REGION, and AUTH_KEY with values from the CometChat Dashboard. Auth Key is optional — use Auth Token for production.

Setting Session Storage Mode

To use session storage instead of the default local storage, configure it during initialization:

Get Logged In User

Checks for an existing session in the SDK. Returns the logged-in user details or null.

Login using Auth Key

Simple authentication for development/POC. For production, use Auth Token.

Login using Auth Token

Production-safe authentication that does not expose the Auth Key in client code.
  1. Create a User via the CometChat API when the user signs up in your app.
  2. Create an Auth Token via the CometChat API for the new user and save the token in your database.
  3. Load the Auth Token in your client and pass it to the loginWithAuthToken() method.

Logout

Ends the current user session.

Create user

Takes a User object and Auth Key, returns the created User object.

Update user

Takes a User object and Auth Key, returns the updated User object.

Base Message

Text message

Sends a text message in a 1:1 or group chat. Takes a TextMessage object.

Media message

Sends a media message in a 1:1 or group chat. Takes a MediaMessage object.
Replace INPUT FILE OBJECT with the actual File object.

Custom message

Sends a custom message (neither text nor media) in a 1:1 or group chat. Takes a CustomMessage object.