react chat code example

Example 1: react live chat widget

import React from 'react';import { Widget, addResponseMessage } from 'react-chat-widget'; import 'react-chat-widget/lib/styles.css'; function App() {  useEffect(() => {    addResponseMessage('Welcome to this awesome chat!');  }, []);   const handleNewUserMessage = (newMessage) => {    console.log(`New message incoming! ${newMessage}`);    // Now send the message throught the backend API    addResponseMessage(response);  };   return (    <div className="App">      <Widget        handleNewUserMessage={handleNewUserMessage}      />    </div>  );} export default App;

Example 2: chat application in react js

import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom'; // added
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
ReactDOM.render(
  <Router>
    <App />
  </Router>
  , document.getElementById('root'));