CustomGPT.ai Blog

How do I Embed a Chatbot in a React app?

Embed a chatbot in React by either adding a hosted chat widget script in public/index.html, installing a React chatbot component from npm, or rendering an iframe. With CustomGPT.ai, create an agent, copy the Live Chat or iframe code, and paste it into your React app’s layout. Scope: Last updated: December 2025. Applies globally; verify chatbot tracking, cookies, and personal data handling against local privacy laws such as GDPR in the EU and CCPA/CPRA in California.

Prerequisites for embedding a chatbot in React

Before you add any chatbot, you need a working React project with Node.js and npm (or yarn/pnpm) set up. A typical app is created with tools like Create React App or Vite, which give you an index.html shell and a root React component.  The chatbot UI is usually mounted either:
  • globally, via a script tag in public/index.html, or
  • inside your React component tree (for example in App.tsx or a layout shell), if you’re using a React webchat component.
Make sure you can run npm start (or your dev command), and you’re comfortable editing JSX/TSX files before proceeding. 

Common ways to embed a chatbot in a React app

In practice, there are three common patterns:
  1. Hosted chat widget via script Your chatbot platform gives you a <script> snippet. You paste this into your site’s HTML so it injects a floating button or chat window. This is the simplest no-code option. 
  2. React chatbot component/library Some platforms provide a React SDK or component library (for example, a <Webchat /> React component) that you install from npm and render within your React tree.
  3. Embedded iframe The provider gives you an iframe URL and/or embed code. You wrap it in a React component and control sizing and responsiveness yourself. This is very generic and works with almost any hosted chatbot.
Each method trades off ease of setup, customization, and how tightly it integrates with your React state and routing.

Method 1 — Add a hosted chat widget script

This is the “copy–paste a snippet” approach most non-technical teams start with. Steps
  1. Get the script snippet from your chatbot provider In your provider’s dashboard, look for “Install on website”, “Widget code”, or “Live Chat”. You’ll usually get a <script> tag and maybe a small <div> placeholder.
  2. Open your React app’s HTML shell For Create React App, open public/index.html. For Vite or other tools, open the main HTML file where the React root is declared.
  3. Paste the script before the closing </body> This ensures the DOM is loaded first and the widget then injects itself into the page without blocking rendering.
  4. Restart your dev server and verify the widget Run your dev command (npm start, npm run dev, etc.). Load the app in a browser and confirm the chat bubble appears on every page.
  5. Optionally restrict it to specific routes If the provider supports programmatic initialization, you can skip index.html and instead insert the script using a top-level React component that only renders on certain routes, or toggles the widget on/off in effect hooks.
This method is fast and works even if your chatbot platform isn’t React-aware, but you have less control from inside React components.

Method 2 — Use a React chatbot component library

If you prefer everything to live in React, use a React-native webchat library. Steps
  1. Choose a React-compatible webchat SDK Some providers offer a dedicated React webchat library that you install from npm and use like any other component. For example, Botpress has a Webchat React library that requires React 18+.
  2. Install the package From your project root, run a command like:
npm install @botpress/webchat
  1. Wrap your app with any required provider Many SDKs expose a context provider (for example, WebchatProvider) that you place high in your component tree to initialize the client and theme.
  2. Render the chat component where you want it In your layout or page component, add the chat UI:
import { Webchat } from ‘@botpress/webchat’; function Layout() { return ( <> {/* page content */} <Webchat configuration={/* your bot config */} /> </> ); } “` :contentReference[oaicite:8]{index=8}
  1. Pass configuration, user info, and handlers Use props or hooks to pass bot IDs, theme options, and handlers for events like “message sent” or “conversation started”. Some SDKs provide hooks (such as useWebchat) for deeper control of conversation state. 
  2. Style the chat component Use the library’s theming options or your own CSS/utility classes to match your app’s design.
This approach gives you full React integration, but it depends on the platform supporting a React SDK.

Method 3 — Embed a chatbot with an iframe

Use this method when your provider exposes a hosted chat page or iframe snippet. Steps
  1. Get the iframe embed code or URL Your chatbot provider should offer an “Embed via iframe” option that gives you a <iframe src=”…”> snippet and recommended dimensions.
  2. Create a reusable ChatbotIframe component For example:
const ChatbotIframe = () => ( <iframe src=“https://your-chat-provider.com/agent/123” style= width: ‘100%’, height: ‘100%’, border: ‘none’ title=“Support chatbot” /> );
  1. Place the component in your layout or page You can embed it as a full-screen support page or inside a sidebar/drawer.
  2. Handle responsiveness Use CSS or responsive utilities to ensure the iframe looks good on smaller screens. You can constrain height with a fixed vh value or flexbox container.
  3. Be aware of refresh behavior Because the chat is in an iframe, refreshing the page usually resets the conversation session. Some providers (including CustomGPT.ai) explicitly note this limitation for iframe embeds.
This method is extremely flexible and works with almost any SaaS chatbot, but is more isolated from your React state and routing logic.

How to do it with CustomGPT.ai

CustomGPT.ai lets you build an AI agent from your content, then deploy it as a Live Chat widget or iframe embed that works seamlessly in React apps.

Option A — Live Chat widget script (floating chat bubble)

  1. Create and configure your agent In the CustomGPT.ai dashboard, create an agent, add your data sources, and customize its behavior and appearance.
  2. Make the agent public and open Live Chat On the agent card, open the menu, click Deploy Agent, and click Make Public. Go to the Live Chat section.
  3. Copy the Live Chat install code In the Live Chat page, copy the HTML script snippet provided under “Add live chat to any website”. This code injects the CustomGPT.ai chat bubble into any site when included in the HTML.
  4. Paste the script into your React app’s HTML shell In your React project (for example, public/index.html), paste the script just before </body>. When your React app loads, the CustomGPT.ai chat bubble will appear on your pages, including local development builds.
  5. Optionally use advanced customization For multilingual or dynamic behavior, follow the CustomGPT.ai Live Chat docs to switch agents or languages via script, still using the same basic embed pattern.

Option B — iframe-embedded CustomGPT.ai agent

  1. Open the agent’s Deploy → Integration tab In the CustomGPT.ai dashboard, open your agent, click Deploy, then go to the Integration tab. 
  2. Copy the iframe code Scroll to the iframe section and click the code icon to copy the generated <iframe> embed code. This points to a hosted CustomGPT.ai chat UI for your agent.
  3. Wrap the iframe in a React component Create a CustomGptIframe.tsx component and paste the iframe attributes into JSX (for example, using style or class names for height/width). Make sure to set title for accessibility.
  4. Embed the component anywhere in your app Add <CustomGptIframe /> to a support page, drawer, or modal as needed. It behaves like any other React component.
  5. Keep session behavior in mind The iframe guide notes that conversation history is not preserved when the page reloads, because the iframe is tied to the page lifecycle. Design navigation accordingly. 
All steps above are documented in the official CustomGPT.ai docs and rely only on the provided embed and Live Chat features. 

Example — Customer support chatbot in a React SPA

Let’s put it together with a realistic scenario. You have a React dashboard for logged-in customers and you want a floating support chatbot that answers questions from your documentation.
  1. Build a CustomGPT.ai agent from your docs In CustomGPT.ai, create an agent and connect your website or documentation URLs so it can answer support questions. 
  2. Customize the agent and enable Live Chat Tweak its tone, suggested prompts, and appearance. Then go to Deploy → Live Chat, make it public, and copy the Live Chat script embed. 
  3. Add the script to public/index.html in your React app Paste the script before </body>. Start your React dev server and confirm that a “Chat” bubble appears in the bottom corner on all routes.
  4. Test the experience in your actual flows Navigate through the dashboard and ask the bot questions you expect from real users. Adjust agent settings in CustomGPT.ai if answers are off.
  5. Iterate on design and placement When ready for production, adjust widget settings (position, colors, greetings) from the CustomGPT.ai dashboard instead of changing your React code.
This approach gives you a fully hosted AI support agent with almost no extra React code, while still living alongside your React UI.

Conclusion

In the end, you’re choosing between fast, bolt-on chat widgets and fully controlled, maintainable integrations inside your product. Customgpt.ai lets you have both: a production-ready AI agent with copy-paste Live Chat or iframe embeds that still plug cleanly into your React architecture and data. Stop juggling half-integrated tools and fragile scripts— embed a CustomGPT.ai chatbot in your React app today and turn every page into an intelligent, support-ready experience.

FAQ’s

How do I embed a CustomGPT.ai chatbot in a React app?

You embed a CustomGPT.ai chatbot in React by creating an agent in the dashboard, then using the Live Chat or iframe deployment options. Copy the provided script or iframe code and paste it into your React app’s HTML shell or a React component. This lets you add a floating chat bubble or an embedded support panel without rewriting your frontend. Configuration changes happen in CustomGPT.ai, so you rarely touch your React code again.

What is the best way to embed a chatbot in a React single-page app?

The best way depends on how much control you need. For quick installation, paste a hosted chat widget script into your React app’s HTML shell so it loads globally. For deeper control, use a React chatbot component library or a dedicated iframe component, which lets you integrate chat UI with your layout, state, and routing while keeping the bot hosted by a provider like CustomGPT.ai.

Frequently Asked Questions

Which embed method should you use in a React app: script widget, React component, or iframe?

Use the method that matches where you want the chatbot to live in your app. Common options are: (1) a hosted chat widget script added to `public/index.html`, (2) a React chatbot component installed from npm and mounted in your component tree (such as `App.tsx` or a layout shell), or (3) an iframe rendered where you want chat to appear. You can create an agent, copy the Live Chat or iframe code, and paste it into your React layout.

Where should chatbot code be added in a React project?

You can mount chatbot code in two main places: globally in `public/index.html` (script-tag approach) or inside the React component tree (for example in `App.tsx` or a layout shell). Before embedding, make sure your React environment is running correctly with Node.js and npm/yarn/pnpm, and that you can run your dev command.

Can you embed the chatbot inline in a specific React page section instead of only using a global widget?

Yes. You can render the chatbot in an iframe within the specific component or section where you want it displayed, rather than only mounting a global script in `index.html`. This lets you control placement at the page or layout level.

What privacy and compliance checks should you do before embedding a chatbot in React?

Verify how chatbot tracking, cookies, and personal data are handled before launch, and check your implementation against local privacy laws. The source specifically calls out GDPR (EU) and CCPA/CPRA (California) as examples to validate against.

3x productivity.
Cut costs in half.

Launch a custom AI agent in minutes.

Instantly access all your data.
Automate customer service.
Streamline employee training.
Accelerate research.
Gain customer insights.

Try 100% free. Cancel anytime.Â