<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Tan Jin - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Tan Jin - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 22:37:18 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/tjtanjin/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Create a React Chatbot – a Step by Step Guide ]]>
                </title>
                <description>
                    <![CDATA[ In the ever-evolving realm of web technologies, the integration of AI-powered chatbots has become a defining trend in 2024.  With rapid advancements in Large Language Models (LLMs), chatbots have grown to become pivotal tools adopted across many webs... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-a-react-chatbot/</link>
                <guid isPermaLink="false">66c770a059843c48e8082e5b</guid>
                
                    <category>
                        <![CDATA[ #chatbots ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tan Jin ]]>
                </dc:creator>
                <pubDate>Fri, 10 May 2024 22:27:30 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/05/rcb-logo-large---Copy.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In the ever-evolving realm of web technologies, the integration of AI-powered chatbots has become a defining trend in 2024. </p>
<p>With rapid advancements in Large Language Models (LLMs), chatbots have grown to become pivotal tools adopted across many websites and services. From FAQ bots to live chat support, they can provide users with information and assistance.</p>
<p>If you have a website, a sleek chatbot interface can offer support to your users. And you'll want to present a modern chatbot that can captivate your users and leave an impression. </p>
<p>React is one of the most popular tools for developing websites, and React-powered sites and apps are great candidates for chatbots. In this short guide, you'll see how easy it can be to integrate a chatbot into your React website.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Before we start setting up our chatbot, note that this guide assumes knowledge of the following:</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/react-for-beginners-handbook/">React</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/free-8-hour-node-express-course/">Node.js/npm</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/helpful-linux-commands-you-should-know/">Linux Commands</a></li>
</ul>
<p>A basic understanding of the above is sufficient, and you should be able to set up your own React project. If you're completely unfamiliar with the above, you can check out the linked tutorials (as well as any other helpful resources you find) for them first. Otherwise, let's begin!</p>
<h2 id="heading-step-1-create-a-project">Step 1: Create a Project</h2>
<p>Before we can setup our chatbot, let's create a new blank React project. Head over to a project folder of your choice and run the following commands in your terminal:</p>
<pre><code class="lang-bash">npm create vite@latest
</code></pre>
<p>You will be prompted to enter a project name, framework, and variant. For the purpose of this tutorial, we will go with the following selections:</p>
<ul>
<li>Project Name: MyChatBot</li>
<li>Framework: React</li>
<li>Variant: JavaScript</li>
</ul>
<p>Once your setup is complete, head into your project folder and run the following commands:</p>
<pre><code class="lang-bash">npm install &amp;&amp; npm run dev
</code></pre>
<p>If you visit <em>http://localhost:5173</em> on your browser, you should be greeted with the following screen:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/image-16.png" alt="Image" width="600" height="400" loading="lazy">
<em>React app set up</em></p>
<h2 id="heading-step-2-install-react-chatbotify">Step 2: Install React ChatBotify</h2>
<p>Now that we have our project setup, it's time to install <a target="_blank" href="https://react-chatbotify.tjtanjin.com/">React ChatBotify</a>. React ChatBotify is a highly customizable React library that simplifies the process of integrating a chatbot into your application. We'll be using it to include a chatbot so install it with the command below:</p>
<pre><code class="lang-bash">npm install react-chatbotify
</code></pre>
<p>Once the installation is complete, we can proceed to import the library and have it rendered. Within your <code>src</code> folder, open up your <code>App.jsx</code> file with an editor of your choice. The default file should look similar to this:</p>
<pre><code class="lang-app.jsx">import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'

function App() {
  const [count, setCount] = useState(0)

  return (
    &lt;&gt;
      &lt;div&gt;
        &lt;a href="https://vitejs.dev" target="_blank"&gt;
          &lt;img src={viteLogo} className="logo" alt="Vite logo" /&gt;
        &lt;/a&gt;
        &lt;a href="https://react.dev" target="_blank"&gt;
          &lt;img src={reactLogo} className="logo react" alt="React logo" /&gt;
        &lt;/a&gt;
      &lt;/div&gt;
      &lt;h1&gt;Vite + React&lt;/h1&gt;
      &lt;div className="card"&gt;
        &lt;button onClick={() =&gt; setCount((count) =&gt; count + 1)}&gt;
          count is {count}
        &lt;/button&gt;
        &lt;p&gt;
          Edit &lt;code&gt;src/App.jsx&lt;/code&gt; and save to test HMR
        &lt;/p&gt;
      &lt;/div&gt;
      &lt;p className="read-the-docs"&gt;
        Click on the Vite and React logos to learn more
      &lt;/p&gt;
    &lt;/&gt;
  )
}

export default App
</code></pre>
<p>Next, with just adding 2 lines of code, we will see the chatbot rendered in our application. At the top of your file, add the line:</p>
<ul>
<li><code>import ChatBot from 'react-chatbotify'</code></li>
</ul>
<p>Above your <code>&lt;div&gt;</code> element in the <code>return</code> statement, add the following line:</p>
<ul>
<li><code>&lt;ChatBot/&gt;</code></li>
</ul>
<p>Your edited file should look like this:</p>
<pre><code class="lang-app.jsx">import ChatBot from 'react-chatbotify'
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'

function App() {
  const [count, setCount] = useState(0)

  return (
    &lt;&gt;
      &lt;ChatBot/&gt;
      &lt;div&gt;
        &lt;a href="https://vitejs.dev" target="_blank"&gt;
          &lt;img src={viteLogo} className="logo" alt="Vite logo" /&gt;
        &lt;/a&gt;
        &lt;a href="https://react.dev" target="_blank"&gt;
          &lt;img src={reactLogo} className="logo react" alt="React logo" /&gt;
        &lt;/a&gt;
      &lt;/div&gt;
      &lt;h1&gt;Vite + React&lt;/h1&gt;
      &lt;div className="card"&gt;
        &lt;button onClick={() =&gt; setCount((count) =&gt; count + 1)}&gt;
          count is {count}
        &lt;/button&gt;
        &lt;p&gt;
          Edit &lt;code&gt;src/App.jsx&lt;/code&gt; and save to test HMR
        &lt;/p&gt;
      &lt;/div&gt;
      &lt;p className="read-the-docs"&gt;
        Click on the Vite and React logos to learn more
      &lt;/p&gt;
    &lt;/&gt;
  )
}

export default App
</code></pre>
<p>Try running your application again and you'll be greeted with a chatbot on the bottom right corner as shown in the screenshot below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/image-17.png" alt="Image" width="600" height="400" loading="lazy">
<em>Chatbot in the React app</em></p>
<p>Pretty neat, isn't it?</p>
<h2 id="heading-step-3-craft-your-hello-world-message">Step 3: Craft Your "Hello World" Message</h2>
<p>It's nice to have the chatbot setup easily, but it's not great to only have the default welcome message. Let's quickly add a <strong>hello world</strong> message of our own.</p>
<p>The <code>&lt;ChatBot/&gt;</code> component takes in a <code>flow</code> prop to define conversations. By default, the entry point of a conversation is always named the <code>start</code> block as shown in this example below:</p>
<pre><code><span class="hljs-keyword">const</span> flow = {
  <span class="hljs-string">"start"</span>: {
    <span class="hljs-string">"message"</span>: <span class="hljs-string">"Hello world!"</span>
  }
}
</code></pre><p>We will go ahead and pass the above flow into our chatbot:</p>
<pre><code><span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>
<span class="hljs-keyword">import</span> reactLogo <span class="hljs-keyword">from</span> <span class="hljs-string">'./assets/react.svg'</span>
<span class="hljs-keyword">import</span> viteLogo <span class="hljs-keyword">from</span> <span class="hljs-string">'/vite.svg'</span>
<span class="hljs-keyword">import</span> ChatBot <span class="hljs-keyword">from</span> <span class="hljs-string">"react-chatbotify"</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>)

  <span class="hljs-keyword">const</span> flow = {
    <span class="hljs-string">"start"</span>: {
      <span class="hljs-string">"message"</span>: <span class="hljs-string">"Hello world!"</span>
    }
  }
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://vitejs.dev"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">{viteLogo}</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"logo"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Vite logo"</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://react.dev"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">{reactLogo}</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"logo react"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"React logo"</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Vite + React<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setCount((count) =&gt; count + 1)}&gt;
          count is {count}
        <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
          Edit <span class="hljs-tag">&lt;<span class="hljs-name">code</span>&gt;</span>src/App.jsx<span class="hljs-tag">&lt;/<span class="hljs-name">code</span>&gt;</span> and save to test HMR
        <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"read-the-docs"</span>&gt;</span>
        Click on the Vite and React logos to learn more
      <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ChatBot</span> <span class="hljs-attr">flow</span>=<span class="hljs-string">{flow}/</span>&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App
</code></pre><p>When you look at your application again, you will notice that the default message has disappeared and is replaced with <code>Hello world!</code> instead. Not too hard, isn't it? </p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this guide, you've seen how easy it can be to setup a modern React chatbot. </p>
<p>While the example above is simple, there are plenty of other properties within a <code>flow</code> that can help you build your conversations. These are documented on the <a target="_blank" href="https://react-chatbotify.tjtanjin.com/docs/introduction/quickstart">library website</a> which also comes with <a target="_blank" href="https://react-chatbotify.tjtanjin.com/docs/examples/basic_form">live playground examples</a> for you to explore and find out more. </p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
