Use 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. Never expose Auth Keys in production client code.
Initializes the CometChat React Native 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.
JavaScript
Report incorrect code
Copy
Ask AI
import { CometChatUIKit, UIKitSettings } from "@cometchat/chat-uikit-react-native";const uikitSettings = new UIKitSettings({ appId: "APP_ID", // Replace with your App ID region: "REGION", // Replace with your App Region ("eu" or "us") authKey: "AUTH_KEY", // Replace with your Auth Key (optional for Auth Token flow)});CometChatUIKit.init(uikitSettings) .then(() => { console.log("Initialization completed successfully"); }) .catch((error) => { console.log("Initialization failed with exception:", error); });
Sends a Form message which is an extension of Interactive Message.
1:1 Chat
Group Chat
Report incorrect code
Copy
Ask AI
import { CometChat } from "@cometchat/chat-sdk-react-native";import { CometChatUIKit } from "@cometchat/chat-uikit-react-native";const receiverID = "UID";// Create an instance of APIActionlet apiAction = new APIAction("https://example.com/api", "POST");// Create an instance of ButtonElementlet submitButton = new ButtonElement("1", apiAction, "Submit");// Create an instance of TextInputlet nameInput = new TextInputElement("1", "Please enter your name");// Create a new instance of FormMessagelet formMessage = new FormMessage( receiverID, CometChat.RECEIVER_TYPE.USER, "Title", [nameInput], submitButton);CometChatUIKit.sendFormMessage(formMessage) .then((message) => { console.log("Form message sent successfully", message); }) .catch(console.log);
Report incorrect code
Copy
Ask AI
import { CometChat } from "@cometchat/chat-sdk-react-native";import { CometChatUIKit } from "@cometchat/chat-uikit-react-native";const receiverID = "GUID";// Create an instance of APIActionlet apiAction = new APIAction("https://example.com/api", "POST");// Create an instance of ButtonElementlet submitButton = new ButtonElement("1", apiAction, "Submit");// Create an instance of TextInputlet nameInput = new TextInputElement("1", "Please enter your name");// Create a new instance of FormMessagelet formMessage = new FormMessage( receiverID, CometChat.RECEIVER_TYPE.GROUP, "Title", [nameInput], submitButton);CometChatUIKit.sendFormMessage(formMessage) .then((message) => { console.log("Form message sent successfully", message); }) .catch(console.log);
Sends a Card message which is an extension of Interactive Message.
1:1 Chat
Group Chat
Report incorrect code
Copy
Ask AI
import { CometChat } from "@cometchat/chat-sdk-react-native";import { CometChatUIKit } from "@cometchat/chat-uikit-react-native";const receiverID = "UID";// Create instance of ButtonElement for card actionslet cardAction = new ButtonElement( "1", new APIAction("https://example.com/api", "POST"), "Click Me");// Create a new instance of CardMessagelet cardMessage = new CardMessage( receiverID, CometChat.RECEIVER_TYPE.USER, "This is a card", [cardAction]);CometChatUIKit.sendCardMessage(cardMessage) .then((message) => { console.log("Card message sent successfully", message); }) .catch(console.log);
Report incorrect code
Copy
Ask AI
import { CometChat } from "@cometchat/chat-sdk-react-native";import { CometChatUIKit } from "@cometchat/chat-uikit-react-native";const receiverID = "GUID";// Create instance of ButtonElement for card actionslet cardAction = new ButtonElement( "1", new APIAction("https://example.com/api", "POST"), "Click Me");// Create a new instance of CardMessagelet cardMessage = new CardMessage( receiverID, CometChat.RECEIVER_TYPE.GROUP, "This is a card", [cardAction]);CometChatUIKit.sendCardMessage(cardMessage) .then((message) => { console.log("Card message sent successfully", message); }) .catch(console.log);