I am trying this tutorial for the react chat and keep getting the error
TypeError: n.props.handleNewUserMessage is not a function
I tried to resolve it using the following resources:
- https://www.reddit.com/r/reactjs/comments/6fd6nl/keep_getting_error_thispropsonsearch_in_not_a/?st=jhiugk4d&sh=fabd3cc4
- ReactJS with ES6: this.props is not a function when I communicate two components
- React TypeError this._test is not a function
- React does not recognize my function
This is my code:
import React, { Component } from 'react';
import { Widget, addResponseMessage } from 'react-chat-widget';
import 'react-chat-widget/lib/styles.css';
class App extends Component {
componentDidMount() {
addResponseMessage("How can I help you?");
}
handleNewUserMessage = (newMessage) => {
console.log(`New message incomig! ${newMessage}`);
// Now send the message throught the backend API
addResponseMessage('response');
}
render() {
return (
<div className="App">
<Widget />
</div>
);
}
}
export default App;
Where have I gone wrong?