> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting Started

> Getting Started — CometChat documentation.

## Start your first conversation

The CometChat UI Kit for React simplifies the process of integrating in-app chat functionality with essential messaging features. With a collection of prebuilt UI components, it offers seamless theming options, including light and dark themes, various fonts, colors, and extensive customization possibilities.

Supporting both one-to-one and group conversations, the CometChat UI Kit for React empowers developers to initiate chat functionalities effortlessly. Follow the guide below to begin implementing chat features into your React applications using CometChat React UI Kit.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/Gp90C5sdVtuRR4t7/images/849be39e-intro_web_screens-d1702576c4ab3f961a1937dcbca01a8b.png?fit=max&auto=format&n=Gp90C5sdVtuRR4t7&q=85&s=4a366cf2166134d88bb579eef1d6ee12" width="3600" height="2400" data-path="images/849be39e-intro_web_screens-d1702576c4ab3f961a1937dcbca01a8b.png" />
</Frame>

## Prerequisites

Before installing **UI Kit** for React, you need to create a CometChat application on the CometChat Dashboard, which comprises everything required in a chat service including users, groups, calls & messages. You will require the `App ID`, `AuthKey`, and `Region` of your CometChat application when initializing the **UI Kit**.

**i. Register on CometChat**

* You need to register on the **CometChat Dashboard** first. [Click here to sign up](https://app.cometchat.com/login).

**ii. Get Your Application Keys**

* Create a **new app**
* Head over to the **QuickStart** or **API & Auth Keys section** and note the **App ID**, **Auth Key**, and **Region**.

<Info>
  Each CometChat application can be integrated with a single client app. Within the same application, users can communicate with each other across all platforms, whether they are on mobile devices or on the web.
</Info>

**iii. IDE Setup**

* You have Node.js installed on your machine.
* You have a code editor like Visual Studio Code or Atom installed.
* You have npm or Yarn installed.

***

### Built With

* [Node](https://nodejs.org/)
* [npm](https://www.npmjs.com/get-npm)
* [React](https://www.npmjs.com/package/react) `npm install react@18.2.0`
* [React DOM](https://www.npmjs.com/package/react-dom) `npm install react-dom@18.0.2`

***

## Getting Started

<Steps>
  <Step title="Step 1">
    ### Create a project

    To get started with React, follow these steps:

    1. Open your code editor.
    2. Create a new project by initializing a new React application using Create React App or any other boilerplate.
    3. Navigate to your project directory and open the project in your code editor.
    4. Begin developing your React application in the "src" directory.
    5. Install additional dependencies as required.
  </Step>

  <Step title="Step 2">
    ### Add Dependency

    This developer kit is an add-on feature to CometChat JavaScript SDK, so installing it will also install the core Chat SDK.

    ```bash theme={null}
    npm install @cometchat/chat-uikit-react@4.x
    ```

    <Note>
      If your npm version is 3 through 6, install the below-mentioned peer dependencies as well.
    </Note>

    ```bash theme={null}
    npm install @cometchat/uikit-elements @cometchat/uikit-resources @cometchat/uikit-shared
    ```
  </Step>

  <Step title="Step 3">
    ### Initialize CometChatUIkit

    The [Init](/ui-kit/react/v4/methods#init) method initialises the settings required for CometChat. Please ensure to call this method before invoking any other methods from CometChat UI Kit or CometChat SDK.

    <Note>
      The Auth Key is an optional property of the `UIKitSettings` Class. It is intended for use primarily during proof-of-concept (POC) development or in the early stages of application development. You can use the [Auth Token](/ui-kit/react/v4/methods#login-using-auth-token) method to log in securely.
    </Note>

    ```javascript theme={null}
    import { UIKitSettingsBuilder } from "@cometchat/uikit-shared";
    import { CometChatUIKit } from "@cometchat/chat-uikit-react";

    const COMETCHAT_CONSTANTS = {
      APP_ID: "APP_ID", //Replace with your App ID
      REGION: "REGION", //Replace with your App Region
      AUTH_KEY: "AUTH_KEY", //Replace with your Auth Key or leave blank if you are authenticating using Auth Token
    };

    //create the builder
    const UIKitSettings = new UIKitSettingsBuilder()
      .setAppId(COMETCHAT_CONSTANTS.APP_ID)
      .setRegion(COMETCHAT_CONSTANTS.REGION)
      .setAuthKey(COMETCHAT_CONSTANTS.AUTH_KEY)
      .subscribePresenceForAllUsers()
      .build();

    //Initialize CometChat UI Kit
    CometChatUIKit.init(UIKitSettings)
      .then(() => {
        console.log("Initialization completed successfully");
        // You can now call login function.
      })
      .catch(console.log);
    ```

    <Info>
      Make sure to replace the **APP\_ID** with your CometChat appId, **AUTH\_KEY** with your CometChat app auth key and **REGION** with your app region in the above code.
    </Info>

    <Note>
      You can choose between different storage methods to store data. By default, we use local storage. To learn more about available storage options and how to configure them, [click here](/ui-kit/react/v4/methods#setting-session-storage-mode).
    </Note>
  </Step>

  <Step title="Step 4">
    ### Login User

    For login, you require a `UID`. You can create your own users on the CometChat Dashboard or via API. We have pre-generated test users: `cometchat-uid-1`, `cometchat-uid-2`, `cometchat-uid-3`, `cometchat-uid-4`, `cometchat-uid-5`.

    The [Login](/ui-kit/react/v4/methods#login-using-auth-key) method returns the User object containing all the information of the logged-in user.

    <Note>
      This straightforward authentication method is ideal for proof-of-concept (POC) development or during the early stages of application development. For production environments, however, we strongly recommend using an [Auth Token](/ui-kit/react/v4/methods#login-using-auth-token) instead of an Auth Key to ensure enhanced security.
    </Note>

    <Tabs>
      <Tab title="JavaScript">
        ```javascript theme={null}
        import { CometChatUIKit } from "@cometchat/chat-uikit-react";

        const UID = "UID"; //Replace with your UID

        CometChatUIKit.getLoggedinUser().then((user) => {
          if (!user) {
            //Login user
            CometChatUIKit.login(UID)
              .then((user) => {
                console.log("Login Successful:", { user });
                //mount your app
              })
              .catch(console.log);
          } else {
            //mount your app
          }
        });
        ```
      </Tab>

      <Tab title="TypeScript">
        ```typescript theme={null}
        import { CometChatUIKit } from "@cometchat/chat-uikit-react";

        const UID = "UID"; //Replace with your UID

        CometChatUIKit.getLoggedinUser().then((user: CometChat.User) => {
          if (!user) {
            //Login user
            CometChatUIKit.login(UID)
              .then((user: CometChat.User) => {
                console.log("Login Successful:", { user });
                //mount your app
              })
              .catch(console.log);
          } else {
            //mount your app
          }
        });
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Step 5">
    ### Render Conversation With Message

    [ConversationsWithMessages](/ui-kit/react/v4/conversations-with-messages) is a wrapper component that offers functionality to render both the [Conversations](/ui-kit/react/v4/conversations) and [Messages](/ui-kit/react/v4/messages) components. It also enables opening the [Messages](/ui-kit/react/v4/messages) by tapping on any conversation rendered in the list of conversations.

    <Frame>
      <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/Gp90C5sdVtuRR4t7/images/849be39e-intro_web_screens-d1702576c4ab3f961a1937dcbca01a8b.png?fit=max&auto=format&n=Gp90C5sdVtuRR4t7&q=85&s=4a366cf2166134d88bb579eef1d6ee12" width="3600" height="2400" data-path="images/849be39e-intro_web_screens-d1702576c4ab3f961a1937dcbca01a8b.png" />
    </Frame>

    [ConversationsWithMessages](/ui-kit/react/v4/conversations-with-messages) can be rendered by adding the following code snippet to the \`App.js\`\` file:

    ```javascript theme={null}
    import { CometChatConversationsWithMessages } from "@cometchat/chat-uikit-react"; //import the component in your App.js file

    export const App = () => {
      return <CometChatConversationsWithMessages />;
    };
    ```

    <Info>
      It will automatically fetch the conversation data upon loading the list. If the conversation list is empty, you can start a new conversation.
    </Info>
  </Step>

  <Step title="Step 6">
    ### Run the project
  </Step>
</Steps>

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    npm start
    ```
  </Tab>
</Tabs>
