title: How to Fix Unhandled Rejection (TypeError): chat.setUser is not a function in Firechat by Firebase in React.js
body: <p>I am trying to make a Chat application by using <a href="https://firechat.firebaseapp.com/" rel="nofollow noreferrer">Firechat by Firebase</a></p>
  
  <p>I am geting this error. </p>
  
  <pre><code>Unhandled Rejection (TypeError): chat.setUser is not a function
  </code></pre>
  
  <p>Below is the code</p>
  
  <pre><code>import React, { Component } from "react";
  import { FirebaseContext } from "../../firebase";
  import * as FirechatUI from 'firechat';
  
  class PublicChat extends Component {
      static contextType = FirebaseContext;
  
      constructor(props) {
          super(props);
  
      };
  
      componentDidMount() {
  
          var elem = document.getElementById("firechat-wrapper");
  
          var chatRef = this.context.database.ref();
  
          var chat = new FirechatUI(chatRef, elem);
  
          this.context.auth.onAuthStateChanged(function(user) {
          if (user) {
              chat.setUser(user.uid, user.displayName);
              } 
          });
      }
  
  
      render() {
          return (
              &lt;&gt;
              &lt;div id="firechat-wrapper"&gt;&lt;/div&gt;
              &lt;/&gt;
          );
      }
  }
  
  export default PublicChat;
  </code></pre>
  
  <p>..........................................................................................................................</p>