Skip to main content
Render the header for an active chat with name, avatar, status, and typing indicators.

When to use this

  • You need a chat header for a user or group conversation.
  • You want typing indicators and presence in the header.
  • You want to customize the title or back button.

Prerequisites

  • CometChat React UI Kit v6 installed: @cometchat/chat-uikit-react.
  • CometChatUIKit.init() and CometChatUIKit.login() complete before rendering.
  • Provide either user or group (not both).

Quick start

  1. Add the component to your UI.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

export default function MessageHeaderDemo() {
  const [chatUser, setChatUser] = React.useState();

  React.useEffect(() => {
    CometChat.getUser("uid").then((user) => setChatUser(user));
  }, []);

  return chatUser ? <CometChatMessageHeader user={chatUser} /> : null;
}
What this does: Renders the minimal version of the component.
  1. Verify the component renders after init() and login().

Core concepts

  • Pass user for 1:1 or group for group chats.
  • hideBackButton and hideUserStatus control header UI.

Implementation

  • Package: @cometchat/chat-uikit-react
  • Import: import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";
  • Minimal JSX: <CometChatMessageHeader user={chatUser} /> or <CometChatMessageHeader group={chatGroup} />
  • Required setup: CometChatUIKit.init(UIKitSettings) then CometChatUIKit.login("UID")
  • Key props: user: CometChat.User, group: CometChat.Group, hideBackButton: boolean, hideUserStatus: boolean
  • CSS class: .cometchat-message-header

Overview

What you’re changing: Overview. Where to change it: Component props or CSS as shown below. Default behavior: UI Kit defaults. Override: Use the examples in this section. Verify: The UI reflects the change shown below. MessageHeader is a Component that showcases the User or Group details in the toolbar. Furthermore, it also presents a typing indicator and a back navigation button for ease of use.
Before using this component: Ensure CometChatUIKit.init(UIKitSettings) has completed and the user is logged in via CometChatUIKit.login("UID"). See React.js Integration.
The MessageHeader is comprised of the following components:
ComponentDescription
CometChatListItemThis component’s view consists of avatar, status indicator , title, and subtitle. The fields are then mapped with the SDK’s user, group class.
Back ButtonBackButton that allows users to navigate back from the current activity or screen to the previous one.

Usage

What you’re changing: Usage. Where to change it: Component props or CSS as shown below. Default behavior: UI Kit defaults. Override: Use the examples in this section. Verify: The UI reflects the change shown below.

Integration

import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

export function MessageHeaderDemo() {
  const [chatUser, setChatUser] = React.useState<CometChat.User>();
  React.useEffect(() => {
    CometChat.getUser("uid").then((user) => {
      setChatUser(user);
    });
  }, []);

  return chatUser ? (
    <div>{chatUser && <CometChatMessageHeader user={chatUser} />}</div>
  ) : null;
}
What this does: Shows the code for this step.

Actions

Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.
1. OnBack
OnBack is triggered when you click on the back button of the Message Header component. You can override this action using the following code snippet. Example In this example, we are employing the onBack action.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

export function MessageHeaderDemo() {
  const [chatUser, setChatUser] = React.useState<CometChat.User>();
  React.useEffect(() => {
    CometChat.getUser("uid").then((user) => {
      setChatUser(user);
    });
  }, []);

  function handleOnBack() {
    console.log("your custom on back action");
  }

  return chatUser ? (
    <div>
      {chatUser && (
        <CometChatMessageHeader user={chatUser} onBack={handleOnBack} />
      )}
    </div>
  ) : null;
}
What this does: Shows the code for this step.

2. OnError
This action doesn’t change the behavior of the component but rather listens for any errors that occur in the Message Header component. Example In this example, we are employing the onError action.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

export function MessageHeaderDemo() {
  const [chatUser, setChatUser] = React.useState<CometChat.User>();
  React.useEffect(() => {
    CometChat.getUser("uid").then((user) => {
      setChatUser(user);
    });
  }, []);

  function handleError(error: CometChat.CometChatException) {
    throw new Error("your custom error action");
  }
  return chatUser ? (
    <div>
      {chatUser && (
        <CometChatMessageHeader user={chatUser} onError={handleError} />
      )}
    </div>
  ) : null;
}
What this does: Shows the code for this step.

3. onSearchOptionClicked
The onSearchOptionClicked event is triggered when the user clicks the search option. It does not have a default behavior. However, you can override its behavior using the following code snippet.
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

const handleSearchClick = () => {
  console.log("Search option clicked");
};

<CometChatMessageHeader onSearchOptionClicked={handleSearchClick} />;
What this does: Shows the code for this step.

4. OnItemClick
OnItemClick is triggered when you click on a ListItem of the CometChatMessageHeader component. The OnItemClick action doesn’t have a predefined behavior. You can override this action using the following code snippet.
import { MessageHeaderDemo } from "@cometchat/chat-uikit-react";

const getOnItemClick = () => {
  console.log("List item clicked");
};

<MessageHeaderDemo onItemClick={getOnItemClick} />;
What this does: Shows the code for this step.

Filters

Filters allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using RequestBuilders of Chat SDK. The MessageHeader component does not have any exposed filters.

Events

Events are emitted by a Component. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed. The MessageHeader component does not produce any events.

Customization

What you’re changing: Customization. Where to change it: Component props or CSS as shown below. Default behavior: UI Kit defaults. Override: Use the examples in this section. Verify: The UI reflects the change shown below. To fit your app’s design requirements, you can customize the appearance of the Message Header component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.

Style

To customize the appearance, you can customise css of CometChatMessageHeader Example
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

// Assuming groupObj is defined elsewhere in your code
<CometChatMessageHeader group={groupObj} />;
What this does: Shows the code for this step.

Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements. Here is a code snippet demonstrating how you can customize the functionality of the Message Header component.
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

<CometChatMessageHeader user={chatUser} showBackButton={true} />;
What this does: Shows the code for this step.
Following is a list of customizations along with their corresponding code snippets:
PropertyDescriptionCode
Show Back ButtonShows the back button.showBackButton={true}
Hide Video Call ButtonHides the video call button.hideVideoCallButton={true}
Hide Voice Call ButtonHides the voice call button.hideVoiceCallButton={true}
Show Conversation Summary ButtonShows the conversation summary button.showConversationSummaryButton={true}
Hide User StatusHides the user’s online/offline status indicator.hideUserStatus={true}
Show Search OptionShows the search option.showSearchOption={true}
UserA CometChat.User object representing the user whose information (e.g., status) is displayed.user={chatUser}
GroupA CometChat.Group object representing the group whose details (e.g., member count) are displayed.group={chatGroup}
Summary Generation Message CountNumber of messages for which the summary should be shown.summaryGenerationMessageCount={1000}
Disable Auto Summary GenerationDisables the auto generation of conversation summary.disableAutoSummaryGeneration={true}

Advanced

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.
ItemView
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
  CometChatMessageHeader,
  CometChatListItem,
} from "@cometchat/chat-uikit-react";

// Custom list item view definition
const CustomItemView = (
  <>
    <CometChatListItem
      avatarName={chatUser?.getName()}
      avatarURL={chatUser?.getAvatar()}
      title={chatUser?.getName()}
      subtitleView={chatUser?.getStatus()}
    />
  </>
);

<CometChatMessageHeader
  user={chatUser}
  itemView={CustomItemView}
  showBackButton={true}
/>;
What this does: Shows the code for this step.

TitleView
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

// Custom title view component
function CustomTitleView() {
  return (
    <div className="message-header__title-view">
      <span className="message-header__title-view-name">
        {userObj.getName() + " • "}
      </span>
      <span className="message-header__title-view-status">
        {userObj.getStatusMessage()}
      </span>
    </div>
  );
}

<CometChatMessageHeader user={userObj} titleView={CustomTitleView()} />;
What this does: Shows the code for this step.

SubtitleView
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageHeader } from "@cometchat/chat-uikit-react";

// Custom subtitle view component
function CustomSubtitleView() {
  return <>{group?.getMembersCount() + " • " + group?.getDescription()}</>;
}

<CometChatMessageHeader group={groupObj} subtitleView={CustomSubtitleView()} />;
What this does: Shows the code for this step.

LeadingView
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
  CometChatMessageHeader,
  CometChatAvatar,
} from "@cometchat/chat-uikit-react";

// Custom title view component
function CustomLeadingView() {
  return (
    <div className="message-header__leading-view">
      <CometChatAvatar image={userObj?.getAvatar()} name={userObj?.getName()} />
      <span className="message-header__leading-view-role">
        ⭐ {userObj?.getRole()}
      </span>
    </div>
  );
}

<CometChatMessageHeader user={userObj} leadingView={CustomLeadingView()} />;
What this does: Shows the code for this step.

TrailingView
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
  CometChatMessageHeader,
  CometChatButton,
} from "@cometchat/chat-uikit-react";

// Custom trailing view component
function CustomTrailingButtonView() {
  return (
    <>
      <CometChatButton
        onClick={() => {
          // Your logic here
        }}
        iconURL={icon} // Ensure `icon` is defined or passed as a prop
      />
    </>
  );
}

<CometChatMessageHeader
  user={userObj}
  trailingView={CustomTrailingButtonView()}
/>;
What this does: Shows the code for this step.

AuxiliaryButtonView
The customized chat interface is displayed below.
Use the following code to achieve the customization shown above.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
  CometChatMessageHeader,
  CometChatButton,
} from "@cometchat/chat-uikit-react";

// Custom auxiliary view component
function CustomAuxiliaryButtonView() {
  return (
    <>
      <CometChatButton
        onClick={() => {
          // Your logic here
        }}
        iconURL={icon} // Ensure `icon` is defined or passed as a prop
      />
    </>
  );
}

<CometChatMessageHeader
  group={groupObj}
  auxiliaryButtonView={CustomAuxiliaryButtonView()}
/>;
What this does: Shows the code for this step.
LastActiveAt Date Time Format
The lastActiveAtDateTimeFormat property allows you to customize the last active timestamp displayed in the message header. Default Date Time Format:
new CalendarObject({
  today: `[Last seen DD MMM at] hh:mm A`, // Example: "today at 10:30 AM"
  yesterday: `[Last seen DD MMM at] hh:mm A`, // Example: "yesterday at 08:15 PM"
  otherDays: `[Last seen DD MMM at] hh:mm A`, // Example: "25, Jan 05:45 PM"
  relativeTime: {
    hour: `Last seen  %d hour ago`, // Example: "1 hour ago"
    minute: `Last seen  %d minute ago`, // Example: "1 minute ago"
    minutes: `Last seen  %d minutes ago`, // Example: "5 minutes ago"
  },
});
What this does: Shows the code for this step. The following example demonstrates how to modify the last active timestamp format using a custom CalendarObject.
import {
  CometChatMessageHeader,
  CalendarObject,
} from "@cometchat/chat-uikit-react";

// Define a custom date format pattern
function getDateFormat() {
  const dateFormat = new CalendarObject({
    today: `hh:mm A`, // Example: "10:30 AM"
    yesterday: `[yesterday]`, // Example: "yesterday"
    otherDays: `DD MM YYYY`, // Example: "25 01 2025"
  });
  return dateFormat;
}

// Apply the custom format to the CometChatMessageHeader component
<CometChatMessageHeader
  group={groupObj}
  lastActiveAtDateTimeFormat={getDateFormat()}
/>;
What this does: Shows the code for this step.
Fallback Mechanism
  • If you do not pass any property in the CalendarObject, the component will first check the global configuration. If the property is also missing in the global configuration, it will fallback to the component’s default formatting.

SymptomCauseFix
Component doesn’t renderCometChatUIKit.init() not called or not awaitedEnsure init completes before rendering. See Methods
Component renders but shows no dataUser not logged inCall CometChatUIKit.login("UID") after init
Typing indicator not showingNo active typing in the conversationTyping indicator appears only when the other user is actively typing
Back button not visiblehideBackButton={true} is setRemove or set hideBackButton={false}
SSR hydration errorComponent uses browser APIs on serverWrap in useEffect or dynamic import with ssr: false. See Next.js Integration

Customization matrix

What you want to changeWhereProperty/APIExample
Hide back buttonCometChatMessageHeaderhideBackButtonhideBackButton={true}
Hide statusCometChatMessageHeaderhideUserStatushideUserStatus={true}
Custom title viewCometChatMessageHeadertitleViewtitleView={() => <MyTitle />}

Common pitfalls and fixes

SymptomCauseFix
Header does not renderInit/login not completeCall CometChatUIKit.init() and login() first
Missing name/avatarUser/group not loadedFetch CometChat.User or CometChat.Group
Both user and group passedInvalid propsPass only one of user or group

FAQ

Can I hide the back button? Yes. Use hideBackButton={true}. Does it show typing? Yes. Typing indicators are built in.

Next steps