react-simple-chatbot icon indicating copy to clipboard operation
react-simple-chatbot copied to clipboard

Messages duplicate

Open Esshahn opened this issue 3 years ago • 16 comments

Describe the bug Messages are doubled with each new trigger.

To Reproduce Steps to reproduce the behavior:

  1. clean install the repo inside a fresh react app.
  2. use the code example below.

Expected behavior messages should appear only once, as defined in the code. Instead, they appear multiple times (see screenshot)

Desktop (please complete the following information):

  • OS: Mac OS Monterey
  • Browser Latest Chrome, Safari

Bildschirmfoto 2022-06-28 um 15 51 27

Code

import "./App.css";
import ChatBot from "react-simple-chatbot";

function App() {
  const steps = [
    {
      id: "0",
      message: "Message 0",
      trigger: "1",
    },
    {
      id: "1",
      message: "Message 1",
      trigger: "2",
    },
    {
      id: "2",
      message: "Message 2",
      end: true,
    },
  ];

  return (
    <div className="App">
      <ChatBot steps={steps} />
    </div>
  );
}

export default App;

Esshahn avatar Jun 28 '22 13:06 Esshahn

I got the same problem...

krownsh avatar Jul 07 '22 12:07 krownsh

I found out that it's related with create react app, but I don't know why. I switched to Vite and it worked then.

Esshahn avatar Jul 07 '22 12:07 Esshahn

I've investigated more an found the difference that made it work for me. Before I used:

import ReactDOM from "react-dom/client";
ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
)

which produced the error, switching it to

import { render } from "react-dom";
render(<App />, document.getElementById("root"));

made it work. Hope that helps.

Esshahn avatar Jul 07 '22 14:07 Esshahn

Platform: - Next.js File:- next.config.js

#Issue Solve... Solution:- Change reactStrictMode value TRUE to FALSE

======= Code =======

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: false,
  swcMinify: true,
};

module.exports = nextConfig;

Darpan-favfly avatar Jul 25 '22 05:07 Darpan-favfly

With react 18 strict mode enable useEffect to run twice in development, that's why this library might be bugged

ScreamZ avatar Oct 31 '22 17:10 ScreamZ

I've investigated more an found the difference that made it work for me. Before I used:

import ReactDOM from "react-dom/client";
ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
)

which produced the error, switching it to

import { render } from "react-dom";
render(<App />, document.getElementById("root"));

made it work. Hope that helps.

This worked for me thanks!!!

Eduardo-Miguel avatar Nov 26 '22 20:11 Eduardo-Miguel