For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.
Skip to content

React

React chat SDK: 325 kB and two packages, backend included

We added four hosted chat SDKs to four fresh React apps. The cost ran from 325 kB to 918 kB of gzipped code and from 2 to 216 npm packages. TalkJS came in lowest on both, and you still get prebuilt React chat components and the backend that stores and delivers every message between your users.

import { Chatbox } from '@talkjs/react-components';
import '@talkjs/react-components/default.css';

export function Chat() {
  return (
    <Chatbox
      appId="<APP_ID>"
      userId="frank"
      conversationId="new_conversation"
      style={{ height: '600px' }}
    />
  );
}
Frank
Hey, I’m trying to lift state up from a child component, but I’m getting undefined errors. Any ideas?
8m ago
You
Are you passing the state and the setState function correctly as props?
6m ago
Frank
I think so, yes.
5m ago
ok-hand
thinking
You
Maybe you’re not binding the handler in the constructor. That might be the issue.
2m ago
Write a reply…
You
Hi Priya! Do you have a piano lesson free on Thursday?
6m ago
Priya
Yes, 4pm works. Is it for you or your daughter?
4m ago
thumbs-up
You
My daughter. She’s a beginner.
2m ago
Priya
Perfect. I’ll send the booking link here.
just now
Thanks, see you Thursday!
Classtime
Decathlon
Riot Games
Hyundai

React chat SDKs with prebuilt UI components, measured

Every kilobyte here is code your users download before they can chat, and every package is one more lockfile entry to audit and update. We built the same kind of chat screen with TalkJS, Sendbird, Stream, and CometChat.

What one conversation screen adds to a React build

Loads with the pageLazy chunks, load later
TalkJS
TalkJS: 325 kB added to the build325 kB
Sendbird
Sendbird: 395 kB added to the build395 kB
Stream
Stream: 571 kB added to the build571 kB
CometChat
CometChat: 918 kB added to the build918 kB
Gzipped JavaScript and CSS added to an empty Vite 8.3.5 and React 19.3.1 app, November 3, 2026.
MeasureTalkJSSendbirdStreamCometChat
One conversation325 kB395 kB571 kB918 kB
Conversation list and chat325 kB455 kB585 kB918 kB
npm packages added2122166

The screens: TalkJS Chatbox and Inbox from its docs (@talkjs/react-components 0.3.12). Sendbird GroupChannel and App, trimmed by us from its tutorial and README (@sendbird/uikit-react 3.20.0). Stream’s tutorial and Getting Started (stream-chat-react 14.14.1). CometChat’s docs screen, which has a conversation list either way (@cometchat/chat-uikit-react 7.2.5).

These are build sizes. We ran only the TalkJS app. It also loads its fonts and a 14 kB emoji picker from a CDN at run time. For features and prices at 10,000 and 25,000 users, see our chat API comparison.

Keep it off your first load with React.lazy

Most of your pages don’t show a chat, so they shouldn’t download one. Load it where people open it:

import { lazy, Suspense, useState } from 'react';

const Chat = lazy(() => import('./Chat'));

function Messages() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <button onClick={() => setOpen(true)}>Open messages</button>
      {open && (
        <Suspense fallback={<p>Loading chat…</p>}>
          <Chat />
        </Suspense>
      )}
    </>
  );
}

In our build, this kept the first load within 1 kB of an empty app. The chat’s 326 kB, its fonts, and the emoji picker arrive when someone opens it, so the size of the SDK you choose still decides how long they wait. Vite will still print its chunk-size warning, as it did for all four SDKs, because it measures size before gzip.

What TalkJS adds to first load, and what loads after

Loads with the pageLoads when the chat opens
Chatbox, imported directly
Chatbox, imported directly: 325 kB325 kB
Chatbox with React.lazy
Chatbox with React.lazy: 1 kB, then 326 kB when opened1 kB, then 326 kB when opened
Data API, no chat UI
Data API, no chat UI: 55 kB, plus your own UI55 kB, plus your own UI
Gzipped JavaScript and CSS over the same empty app, with @talkjs/core 1.12.1.

Install the official React chat SDK and render a Chatbox

Install the TalkJS React components and the JavaScript Data API:

npm install @talkjs/react-components @talkjs/core

Here’s the code from our React getting started guide. Add your app ID from the dashboard, and it creates two users and a conversation, then opens the conversation in a Chatbox:

import { Chatbox } from '@talkjs/react-components';
import '@talkjs/react-components/default.css';
import { getTalkSession } from '@talkjs/core';
import { useEffect } from 'react';

function Chat() {
  const appId = '<APP_ID>';
  const userId = 'frank';
  const otherUserId = 'nina';
  const conversationId = 'new_conversation';
  const session = getTalkSession({ appId, userId });

  useEffect(() => {
    session.currentUser.createIfNotExists({ name: 'Frank' });
    session.user(otherUserId).createIfNotExists({ name: 'Nina' });

    const conversation = session.conversation(conversationId);
    conversation.createIfNotExists();
    conversation.participant(otherUserId).createIfNotExists();
  }, [session, conversationId, otherUserId]);

  return (
    <Chatbox
      style={{ width: '400px', height: '600px' }}
      appId={appId}
      userId={userId}
      conversationId={conversationId}
    />
  );
}

export default Chat;

That’s a working chat: we ran it in a Vite production build and sent a message through it. Authentication is off on a new app, so you don’t need a token yet. Want the conversation list too? Swap the Chatbox for the Inbox, which takes the same appId and userId, needs no conversationId, and comes out the same size.

Before you go live, turn on authentication so that only your users can open their chats. Your backend signs a token for each user, your app passes it with getTalkSession({ appId, userId }).setToken(token), and you switch on Authentication (identity verification) on the Settings page of your dashboard.

Build your own UI with the React chat API

Got your own chat design? Skip the components. A chat API gives you the messaging data and leaves the UI to you, and ours is the JavaScript Data API. It adds 55 kB on its own, and this hook keeps a conversation’s messages in React state, newest first:

import { getTalkSession } from '@talkjs/core';
import type { MessageSnapshot } from '@talkjs/core';
import { useEffect, useState } from 'react';

const session = getTalkSession({ appId: '<APP_ID>', userId: 'frank' });

function useMessages(conversationId: string) {
  const [messages, setMessages] = useState<MessageSnapshot[]>([]);

  useEffect(() => {
    const subscription = session
      .conversation(conversationId)
      .subscribeMessages((snapshot) => setMessages(snapshot ?? []));
    return () => subscription.unsubscribe();
  }, [conversationId]);

  return messages;
}

Send with session.conversation(id).send('Hello') and the hook updates without a reload. For server tasks, such as syncing users, use the REST API and webhooks.

A React chat library leaves delivery, storage, and notifications to you

UI libraries such as MUI X Chat and KendoReact give you chat screens, and assistant-ui is a frontend for AI agents. They stop at the UI, and for chat between your users, the UI is the smaller part of the job. Having an AI coding agent write the chat doesn’t change that: notifications, moderation, and message history are still yours to build.

We host all of it. Messages are delivered in real time and stored with unlimited history. Someone who misses one gets an email or mobile push notification on every plan, and can reply right from the email. SMS is there too, charged separately. Moderation comes with it: forbidden words, user bans, and automatic hiding of email addresses and phone numbers.

Catawiki logo
We needed chat and didn’t want to build it ourselves because it needs to be really great. The TalkJS team is laser-focused on chat, and we’re focused on building a great auction marketplace.
Dennis Pereira
Head of Product, Catawiki

How far can you customize the React chat UI kit?

From one prop to a theme of your own. Each level is in the customization guide:

  • Props: switch baseTheme or hide the header with chatHeaderVisible
  • CSS: override the default styles
  • One theme component: replace the ChatHeader
  • A full theme: start from the source at github.com/talkjs/themes

More on React: chat UI layouts, the customizable chat component, and the embeddable chat widget.

FAQs

Yes. Next.js apps use the same React components and JavaScript Data API. The Next.js chat page shows how to load them.

Yes, we have separate SDKs for it: @talkjs/react-native for React Native CLI apps (React Native 0.70 or later) and @talkjs/expo for Expo. See the React Native chat page. The components on this page are for React on the web.

@talkjs/react-components 0.3.12 supports React 17, 18, and 19. We built and ran it on React 19.3.1.

Yes, through webhooks and the REST API. A webhook tells your server when a user sends a message, your server calls the AI model you choose, and the REST API posts the reply into the conversation, where your React components show it like any other message. TalkJS doesn’t include a built-in AI agent, so you stay in control of the model and its logic. See the AI agent interface docs, or our React pages on an AI chatbot and an AI agent.

TalkJS is free in development mode with full feature access. You only need a paid plan once you go live with real users. Basic is $279 a month ($239 billed annually) for 10,000 monthly active users. See Pricing.