How to add an AI chatbot to React

On React, a chat widget is installed through public/index.html, before the closing </body> tag. Applies on your next build and deploy. None.

Where it goes

public/index.html, before the closing </body> tag

Availability: None.

Adding the chatbot to React

  1. 1

    Open public/index.html in your project.

  2. 2

    Paste the snippet immediately before the closing </body> tag.

  3. 3

    Rebuild and deploy.

  4. 4

    Applies on your next build and deploy.

The snippet you paste

<script src="https://rubyrep.com/rubyrep.js" data-rubyrep="rr_your_public_key" defer></script>

Your own key replaces rr_your_public_key — you get it after training RubyRep on your site.

Worth knowing on React

  • Putting the script in index.html rather than a component keeps it outside React's render cycle, which is what you want.

  • If you must load it from a component, guard against double-injection in React 18 strict mode, which mounts effects twice in development.

React questions

Where does the code go on React?
public/index.html, before the closing </body> tag. Applies on your next build and deploy.
Do I need a paid React plan?
None.
Will a React update remove it?
Putting the script in index.html rather than a component keeps it outside React's render cycle, which is what you want.
Does it slow React down?
No measurable effect. The snippet is deferred, so it loads after your page has rendered, and the chat interface itself is only fetched when a visitor opens it.

Related

Get your snippet.

Enter your React site and RubyRep reads it, builds your representative, and hands you the exact line to paste.

https://

Takes about a minute. No credit card.

Using something else? See all platforms.