title: TypeError: Cannot read properties of undefined (reading 'state') reactjs
body: <p>I am trying to console log the username and password in onClick in reactjs but I am getting the TypeError. I have definded authenticate function under the constructor of the class. Below is the complete code. Can anyone guide me here?</p>
  <pre><code> authenticate(e){
          e.preventDefault();
          var details = {
              &quot;email&quot; : this.state.username,
              &quot;password&quot; : this.state.password
          }
          alert(details.username + details.password);
  
  
   &lt;input type=&quot;email&quot; onChange = {(event,newValue) =&gt; this.setState({username:newValue})} className=&quot;form-control&quot; name=&quot;email&quot; placeholder=&quot;Enter your Email&quot; required=&quot;required&quot; /&gt;
  
  &lt;input type=&quot;password&quot; onChange = {(event,newValue) =&gt; this.setState({password:newValue})} className=&quot;form-control&quot; name=&quot;password&quot; placeholder=&quot;Enter your Password&quot; required=&quot;required&quot; /&gt;
  
  &lt;button className=&quot;btn w-100 mt-3 mt-sm-4&quot; onClick={this.authenticate} type=&quot;submit&quot;&gt;Sign In&lt;/button&gt;
  </code></pre>