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' }}
/>
);
}

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
| Measure | Sendbird | Stream | CometChat | |
|---|---|---|---|---|
| One conversation | 325 kB | 395 kB | 571 kB | 918 kB |
| Conversation list and chat | 325 kB | 455 kB | 585 kB | 918 kB |
| npm packages added | 2 | 12 | 216 | 6 |
The screens: TalkJS Chatbox and Inbox from its docs (@talkjs/ 0.3.12). Sendbird GroupChannel and App, trimmed by us from its tutorial and README (@sendbird/ 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/ 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
@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/coreHere’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.
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.
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
baseThemeor hide the header withchatHeaderVisible - 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.
