React component

React chat component that's highly customizable

Add real-time chat to your React app in minutes with TalkJS. Our fully-featured chat solution includes customizable pre-built UIs, cross-platform notifications, and flexible theming — no backend setup required.
import { useCallback } from "react";
import Talk from "talkjs";
import { Session, Chatbox } from "@talkjs/react";

function ChatComponent() {
  const syncUser = useCallback(
    () =>
      return new Talk.User({
        id: "nina",
        name: "Nina",
        email: "nina@example.com",
        photoUrl: "https://talkjs.com/new-web/avatar-7.jpg",
        welcomeMessage: "Hi!",
        role: "default",
      }),
    [],
  );

  const syncConversation = useCallback((session) => {
    // JavaScript SDK code here
    const conversation = session.getOrCreateConversation("welcome");

    const other = new Talk.User({
      id: "frank",
      name: "Frank",
      email: "frank@example.com",
      photoUrl: "https://talkjs.com/new-web/avatar-8.jpg",
      welcomeMessage: "Hey, how can I help?",
      role: "default",
    });
    conversation.setParticipant(session.me);
    conversation.setParticipant(other);

    return conversation;
  }, []);

  return (
    <Session appId="<APP_ID>" syncUser={syncUser}>
      <Chatbox
        syncConversation={syncConversation}
        style={{ width: "100%", height: "500px" }}
      ></Chatbox>
    </Session>
  );
}

export default ChatComponent;
Dev A
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
Dev A
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
Dev A
typing...
just now
Write a reply...
SophieTariq
4
Naming conventions
Sophie, Tariq, Liam, Mina
Sophie
Sophie
Quick q: do we prefer CardHeader or HeaderCard for naming this component?
12m ago
Liam
Liam
CardHeader feels more readable to me — keeps the parent/child hierarchy clear.
11m ago
Tariq
Tariq
Agreed. I’d vote CardHeader as well. Feels more natural when scanning component trees.
9m ago
Mina
Mina
Same here. Can we document this in our naming guidelines?
2m ago
thumbsup
memo
Say something...

TalkJS works great for any chat use case

  • 1-on-1 chat
  • Group chat
  • AI chatbots
  • Livestream chat
  • Pretty much any use case
TalkJS is a developer friendly chat API with a pre-built UI that is highly customizable. You can build a chat feature in minutes instead of months.
import { Session, Chatbox } from "@talkjs/react";

<Session appId="t824ba8" userId="pete">
  <Chatbox conversation="workshop" className="chatbox"/>
</Session>

Everything you need for a deeper integration with React

Get to launch quickly with a high-quality default experience, or make use of all the resources you need to build a custom integration with React.
Get notified for each new message via webhooks, control your data with the REST API, or set up email notifications. And if you could use some support in building that integration, you can instantly chat with a TalkJS developer to get some help with your code.