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.

{
  "component": "CometChatConversationStarter",
  "package": "@cometchat/chat-uikit-react",
  "import": "import { CometChatConversationStarter } from \"@cometchat/chat-uikit-react\";",
  "cssImport": "import \"@cometchat/chat-uikit-react/css-variables.css\";",
  "description": "Displays AI-generated conversation starter suggestions as clickable pill-shaped buttons.",
  "cssRootClass": ".cometchat-conversation-starter",
  "subComponents": ["Root", "Item", "Loading", "Error", "Empty"],
  "primaryOutput": {
    "prop": "onSuggestionClick",
    "type": "(suggestion: string) => void"
  },
  "props": {
    "Root": {
      "getConversationStarters": { "type": "() => Promise<string[]>", "note": "Required." },
      "onSuggestionClick": { "type": "(suggestion: string) => void", "default": "undefined" },
      "className": { "type": "string", "default": "undefined" },
      "children": { "type": "ReactNode", "default": "undefined" }
    },
    "Item": {
      "suggestion": { "type": "string", "note": "Required." },
      "onClick": { "type": "(suggestion: string) => void", "default": "undefined" },
      "disabled": { "type": "boolean", "default": "false" },
      "className": { "type": "string", "default": "undefined" }
    },
    "Loading": {
      "count": { "type": "number", "default": "3" },
      "className": { "type": "string", "default": "undefined" },
      "children": { "type": "ReactNode", "default": "undefined" }
    },
    "Error": {
      "message": { "type": "string", "default": "\"Failed to load conversation starters.\"" },
      "onRetry": { "type": "() => void", "default": "undefined" },
      "className": { "type": "string", "default": "undefined" },
      "children": { "type": "ReactNode", "default": "undefined" }
    },
    "Empty": {
      "message": { "type": "string", "default": "undefined" },
      "className": { "type": "string", "default": "undefined" },
      "children": { "type": "ReactNode", "default": "undefined" }
    }
  },
  "types": {
    "CometChatConversationStarterState": "'loading' | 'loaded' | 'error' | 'empty'",
    "CometChatConversationStarterContextValue": {
      "state": "CometChatConversationStarterState",
      "suggestions": "string[]",
      "error": "Error | null",
      "onSuggestionClick": "(suggestion: string) => void | undefined",
      "retry": "() => void"
    }
  }
}

Where It Fits

CometChatConversationStarter is a base component that displays AI-generated conversation suggestions as pill-shaped buttons. It is typically used inside a message composer area or an empty chat view to help users start a conversation. The consumer provides a getConversationStarters function (usually from an AI plugin or custom service), and the component handles loading, error, and empty states automatically.
import { CometChatConversationStarter } from "@cometchat/chat-uikit-react";
import "@cometchat/chat-uikit-react/css-variables.css";

function ChatView() {
  const fetchStarters = () =>
    fetch("/api/ai/starters").then((r) => r.json());

  const handleSuggestionClick = (suggestion: string) => {
    console.log("Send message:", suggestion);
  };

  return (
    <div style={{ maxWidth: 500 }}>
      <CometChatConversationStarter.Root
        getConversationStarters={fetchStarters}
        onSuggestionClick={handleSuggestionClick}
      >
        <CometChatConversationStarter.Loading />
        <CometChatConversationStarter.Error />
        <CometChatConversationStarter.Empty />
      </CometChatConversationStarter.Root>
    </div>
  );
}

Minimal Render

import { CometChatConversationStarter } from "@cometchat/chat-uikit-react";
import "@cometchat/chat-uikit-react/css-variables.css";

function Demo() {
  return (
    <CometChatConversationStarter.Root
      getConversationStarters={() => Promise.resolve(["How are you?", "What's new?"])}
      onSuggestionClick={(s) => console.log(s)}
    >
      <CometChatConversationStarter.Loading />
      <CometChatConversationStarter.Error />
    </CometChatConversationStarter.Root>
  );
}
Root CSS class: .cometchat-conversation-starter

Actions and Events

Callback Props

onSuggestionClick

Called when a user clicks a suggestion button. Receives the suggestion string as the argument.
<CometChatConversationStarter.Root
  getConversationStarters={fetchStarters}
  onSuggestionClick={(suggestion) => {
    sendMessage(suggestion);
  }}
>
  <CometChatConversationStarter.Loading />
</CometChatConversationStarter.Root>

onRetry (Error sub-component)

Called when the user clicks the retry button in the error state. If not provided, the component uses the built-in retry() method from context which re-calls getConversationStarters.
<CometChatConversationStarter.Error
  message="Could not load suggestions"
  onRetry={() => {
    console.log("Retrying...");
  }}
/>

Custom View Slots

SlotSignatureReplaces
Loading{ count?, className?, children? }Shimmer loading state
Error{ message?, onRetry?, className?, children? }Error state view
Empty{ message?, className?, children? }Empty state view

Loading

Renders shimmer placeholder pills while suggestions are being fetched. Defaults to 3 shimmer items.
<CometChatConversationStarter.Loading />

Error

Renders when getConversationStarters rejects. Shows a localized error message and an optional retry button.
<CometChatConversationStarter.Error />

Empty

Renders when getConversationStarters resolves with an empty array. By default renders nothing unless a message or children is provided.
<CometChatConversationStarter.Empty message="No suggestions available" />

Common Patterns

Retry on error

import { CometChatConversationStarter } from "@cometchat/chat-uikit-react";
import "@cometchat/chat-uikit-react/css-variables.css";

function StartersWithRetry() {
  const fetchStarters = () =>
    fetch("/api/ai/starters").then((r) => r.json());

  return (
    <CometChatConversationStarter.Root
      getConversationStarters={fetchStarters}
      onSuggestionClick={(s) => console.log(s)}
    >
      <CometChatConversationStarter.Loading />
      <CometChatConversationStarter.Error message="Failed to load. Try again?" />
      <CometChatConversationStarter.Empty message="No suggestions right now" />
    </CometChatConversationStarter.Root>
  );
}

Using context in custom children

import { useCometChatConversationStarterContext } from "@cometchat/chat-uikit-react";

function CustomSuggestionList() {
  const { state, suggestions, onSuggestionClick } =
    useCometChatConversationStarterContext();

  if (state !== "loaded") return null;

  return (
    <ul>
      {suggestions.map((s) => (
        <li key={s}>
          <button onClick={() => onSuggestionClick?.(s)}>{s}</button>
        </li>
      ))}
    </ul>
  );
}

CSS Architecture

The component uses CSS custom properties (design tokens) defined in @cometchat/chat-uikit-react/css-variables.css. The cascade:
  1. Global tokens set on the .cometchat root wrapper.
  2. Component CSS (.cometchat-conversation-starter) consumes these tokens via var().
  3. Overrides target .cometchat-conversation-starter descendant selectors.

Key Selectors

TargetSelector
Root container.cometchat-conversation-starter
Suggestion pill.cometchat-conversation-starter__item
Suggestion button.cometchat-conversation-starter__item-button
Shimmer container.cometchat-conversation-starter__shimmer-container
Shimmer pill.cometchat-conversation-starter__shimmer-item
Error view.cometchat-conversation-starter__error-view
Retry button.cometchat-conversation-starter__error-retry
Empty view.cometchat-conversation-starter__empty-view
Disabled modifier.cometchat-conversation-starter__item--disabled

Example: Brand-themed conversation starters

App.css
.cometchat-conversation-starter__item {
  border-color: var(--brand-border);
}

.cometchat-conversation-starter__item:hover {
  background: var(--brand-hover);
}

.cometchat-conversation-starter__item-button {
  color: var(--brand-text);
  font-family: var(--brand-font);
}

Customization Matrix

What to changeWhereProperty/APIExample
Data sourceComponent propsgetConversationStarters on Root<Root getConversationStarters={fn}>
Click handlerComponent propsonSuggestionClick on Root<Root onSuggestionClick={fn}>
Loading countComponent propscount on Loading<Loading count={5} />
Error messageComponent propsmessage on Error<Error message="Custom error" />
Retry behaviorComponent propsonRetry on Error<Error onRetry={fn} />
Replace loading UIComponent propschildren on Loading<Loading><Spinner /></Loading>
Replace error UIComponent propschildren on Error<Error><Custom /></Error>
Change visual stylingGlobal CSS.cometchat-conversation-starter selectorsSee example above

Props

All props are optional unless noted otherwise.

CometChatConversationStarter.Root

getConversationStarters

Async function that returns an array of suggestion strings. Called on mount and on retry.
Type() => Promise<string[]>
Defaultundefined
Required.

onSuggestionClick

Called when a suggestion button is clicked. Receives the suggestion string.
Type(suggestion: string) => void
Defaultundefined

className

Custom CSS class appended to the root container.
Typestring
Defaultundefined

children

Sub-components for custom composition (Loading, Error, Empty).
TypeReactNode
Defaultundefined

CometChatConversationStarter.Item

suggestion

The suggestion text to display inside the button.
Typestring
Defaultundefined
Required.

onClick

Called when this specific item is clicked. Receives the suggestion string.
Type(suggestion: string) => void
Defaultundefined

disabled

Whether the item is disabled. Disabled items cannot be clicked and show reduced opacity.
Typeboolean
Defaultfalse

className

Custom CSS class appended to the item container.
Typestring
Defaultundefined

CometChatConversationStarter.Loading

count

Number of shimmer placeholder items to display.
Typenumber
Default3

className

Custom CSS class appended to the shimmer container.
Typestring
Defaultundefined

children

Custom loading content. When provided, replaces the default shimmer animation.
TypeReactNode
Defaultundefined

CometChatConversationStarter.Error

message

Custom error message text. Overrides the default localized error text.
Typestring
Default"Failed to load conversation starters."

onRetry

Callback for the retry button. If not provided, uses the built-in retry() from context.
Type() => void
Defaultundefined

className

Custom CSS class appended to the error container.
Typestring
Defaultundefined

children

Custom error content. When provided, replaces the default error message and retry button.
TypeReactNode
Defaultundefined

CometChatConversationStarter.Empty

message

Text to display when no suggestions are available. If not provided and no children, renders nothing.
Typestring
Defaultundefined

className

Custom CSS class appended to the empty container.
Typestring
Defaultundefined

children

Custom empty content. When provided, replaces the default empty message.
TypeReactNode
Defaultundefined

CSS Selectors

TargetSelector
Root.cometchat-conversation-starter
Suggestion pill.cometchat-conversation-starter__item
Suggestion button.cometchat-conversation-starter__item-button
Disabled item.cometchat-conversation-starter__item--disabled
Shimmer container.cometchat-conversation-starter__shimmer-container
Shimmer pill.cometchat-conversation-starter__shimmer-item
Error view.cometchat-conversation-starter__error-view
Retry button.cometchat-conversation-starter__error-retry
Empty view.cometchat-conversation-starter__empty-view