Transactional

React SDK

Official React SDK for Transactional - Chat, Knowledge Base, Forms, and Auth components.

Installation

Install the React SDK using your preferred package manager:

npm install @usetransactional/react
pnpm add @usetransactional/react
yarn add @usetransactional/react

Then import the base stylesheet in your application entry point:

import '@usetransactional/react/styles.css';

Quick Start

Add a fully functional chat widget to your app in under a minute:

import '@usetransactional/react/styles.css';
import { ChatWidget } from '@usetransactional/react';
 
function App() {
  return (
    <ChatWidget
      inboxId="your-inbox-id"
      user={{
        id: 'user-123',
        email: 'jane@example.com',
        name: 'Jane Doe',
      }}
    />
  );
}

Chat Module

The Chat module provides embeddable live chat components for real-time customer communication.

ChatWidget

The primary component for adding chat to your application. Renders a floating launcher button and an expandable chat window.

import { ChatWidget } from '@usetransactional/react';
 
function App() {
  return (
    <ChatWidget
      inboxId="your-inbox-id"
      user={{
        id: 'user-123',
        email: 'jane@example.com',
        name: 'Jane Doe',
        avatar: 'https://example.com/avatar.jpg',
      }}
      metadata={{
        plan: 'pro',
        company: 'Acme Inc',
      }}
      position="bottom-right"
      launcher={<button>Need help?</button>}
      onOpen={() => console.log('Chat opened')}
      onClose={() => console.log('Chat closed')}
      onNewMessage={(message) => console.log('New message:', message)}
    />
  );
}

Props:

PropTypeRequiredDescription
inboxIdstringYesYour Transactional inbox ID
userUserNoAuthenticated user information
user.idstringYesUnique user identifier
user.emailstringNoUser email address
user.namestringNoDisplay name
user.avatarstringNoAvatar image URL
metadataRecord<string, string>NoCustom metadata attached to the conversation
position"bottom-right" | "bottom-left"NoWidget position on screen. Defaults to "bottom-right"
launcherReactNodeNoCustom launcher element to replace the default button
onOpen() => voidNoCallback when the chat window opens
onClose() => voidNoCallback when the chat window closes
onNewMessage(message: Message) => voidNoCallback when a new message is received

ChatWindow

A standalone chat window component without the floating launcher. Use this when you want to embed chat directly into a page layout rather than as an overlay.

import { ChatWindow } from '@usetransactional/react';
 
function SupportPage() {
  return (
    <div style={{ height: '600px' }}>
      <ChatWindow
        inboxId="your-inbox-id"
        user={{ id: 'user-123', name: 'Jane Doe' }}
      />
    </div>
  );
}

ChatProvider

A context provider that manages chat state. Use this when you need to access chat state or actions from multiple components in your tree.

import { ChatProvider, ChatWindow } from '@usetransactional/react';
 
function App() {
  return (
    <ChatProvider inboxId="your-inbox-id" user={{ id: 'user-123' }}>
      <ChatWindow />
      <MessageCounter />
    </ChatProvider>
  );
}

Knowledge Base Module

The Knowledge Base module provides components for embedding searchable help centers and documentation directly in your application.

KnowledgeBase

The all-in-one knowledge base component that renders a full help center with search, collections, and article views.

import { KnowledgeBase } from '@usetransactional/react';
 
function HelpCenter() {
  return (
    <KnowledgeBase
      projectId="your-project-id"
      theme="system"
      header={<h1>Help Center</h1>}
      hideSearch={false}
      hideCollections={false}
      onArticleView={(article) => console.log('Viewed:', article.title)}
      onSearch={(query) => console.log('Searched:', query)}
    />
  );
}

Props:

PropTypeRequiredDescription
projectIdstringYesYour Transactional project ID
theme"light" | "dark" | "system"NoColor theme. Defaults to "system"
headerReactNodeNoCustom header element
hideSearchbooleanNoHide the search bar
hideCollectionsbooleanNoHide the collections grid
onArticleView(article: Article) => voidNoCallback when an article is viewed
onSearch(query: string) => voidNoCallback when a search is performed

Individual KB Components

For more granular control, use the individual knowledge base components:

import {
  KBProvider,
  KBSearch,
  KBCollections,
  KBArticle,
} from '@usetransactional/react';
 
function CustomHelpCenter() {
  return (
    <KBProvider projectId="your-project-id">
      <div className="search-container">
        <KBSearch />
      </div>
 
      <div className="collections-grid">
        <KBCollections />
      </div>
 
      <div className="article-view">
        <KBArticle articleId="article-slug-or-id" />
      </div>
    </KBProvider>
  );
}

KBSearch - A search input with a results dropdown. Handles debounced search queries and displays matching articles inline.

KBArticle - Renders a single knowledge base article by its ID or slug, including the title, body content, and metadata.

KBCollections - Displays all collections in a list or grid view, with article counts and navigation.

KBProvider - Context provider that manages knowledge base state including the active article, search query, and navigation history. Wrap your individual KB components with this provider.

Forms Module

The Forms module lets you embed Transactional forms directly in your application with automatic validation and submission handling.

TransactionalForm

Renders a complete form by its ID, including all fields, validation rules, and submission logic.

import { TransactionalForm } from '@usetransactional/react';
 
function ContactPage() {
  return (
    <TransactionalForm
      formId="contact-form-id"
      onSubmit={(data) => {
        console.log('Form submitted:', data);
      }}
      onError={(errors) => {
        console.error('Validation errors:', errors);
      }}
    />
  );
}

Props:

PropTypeRequiredDescription
formIdstringYesThe form ID from your Transactional dashboard
onSubmit(data: Record<string, unknown>) => voidNoCallback on successful submission
onError(errors: unknown[]) => voidNoCallback on validation or submission errors

FormField and FormProvider

For advanced use cases, you can compose forms using individual field components:

import { FormProvider, FormField } from '@usetransactional/react';
 
function CustomForm() {
  return (
    <FormProvider formId="contact-form-id">
      <FormField name="email" />
      <FormField name="message" />
      <button type="submit">Send</button>
    </FormProvider>
  );
}

FormField - Renders an individual form field with its label, input, and validation messages.

FormProvider - Context provider that manages form state, validation, and submission. Wrap your FormField components with this provider.

Styling

CSS Variables

Customize the look and feel of all Transactional components by overriding CSS variables in your stylesheet:

:root {
  --transactional-primary: #3b82f6;
  --transactional-primary-hover: #2563eb;
  --transactional-background: #ffffff;
  --transactional-foreground: #09090b;
  --transactional-muted: #f4f4f5;
  --transactional-muted-foreground: #71717a;
  --transactional-border: #e4e4e7;
  --transactional-radius: 0.5rem;
}
VariableDescription
--transactional-primaryPrimary brand color for buttons, links, and accents
--transactional-primary-hoverHover state for primary elements
--transactional-backgroundBackground color for widget surfaces
--transactional-foregroundPrimary text color
--transactional-mutedMuted background for secondary surfaces
--transactional-muted-foregroundMuted text color for secondary content
--transactional-borderBorder color for inputs, cards, and dividers
--transactional-radiusBorder radius for all rounded elements

Component-Specific Stylesheets

If you only use a subset of the SDK, you can import styles per module to reduce your CSS bundle size:

// Chat styles only
import '@usetransactional/react/chat/styles.css';
 
// Knowledge Base styles only
import '@usetransactional/react/kb/styles.css';
 
// Forms styles only
import '@usetransactional/react/forms/styles.css';

Next.js App Router

When using the React SDK with Next.js App Router, all Transactional components must be rendered in a Client Component. Add the 'use client' directive at the top of any file that uses these components:

'use client';
 
import { ChatWidget } from '@usetransactional/react';
 
export default function ChatWrapper() {
  return (
    <ChatWidget
      inboxId="your-inbox-id"
      user={{ id: 'user-123' }}
    />
  );
}

This is required because the SDK uses browser APIs, React state, and effects that are not available in Server Components. A common pattern is to create a thin client wrapper component and import it into your server-rendered layout:

// app/layout.tsx (Server Component)
import ChatWrapper from '@/components/chat-wrapper';
 
export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <ChatWrapper />
      </body>
    </html>
  );
}

TypeScript Types

The SDK exports all relevant types for full type safety:

import type {
  ChatWidgetProps,
  KnowledgeBaseProps,
  TransactionalFormProps,
  User,
  Message,
  Article,
} from '@usetransactional/react';

Key types:

TypeDescription
ChatWidgetPropsProps for the ChatWidget component
KnowledgeBasePropsProps for the KnowledgeBase component
TransactionalFormPropsProps for the TransactionalForm component
UserUser object with id, email, name, and avatar fields
MessageChat message with id, content, sender, timestamp, and type fields
ArticleKnowledge base article with id, title, slug, body, collection, and metadata fields

Requirements

DependencyVersion
React18.0 or higher
React DOM18.0 or higher
Next.js13.0 or higher (optional)