title: ReactJS: Uncaught TypeError: this.setState is not a function
body: <p>While running my app, and when trying to update state with some form values the following error message appears:<br>
  "Uncaught TypeError: this.setState is not a function"</p>
  
  <pre class="lang-js prettyprint-override"><code>LoginForm.onChange
  src/components/forms/LoginForm.js:21
    18 | }
    19 | 
    20 | onChange = e =&gt; {
  &gt; 21 |     this.setState({
       | ^  22 |         data: { ...this.state.data, [e.target.name]: e.target.value }
    23 |     });
    24 | }
  </code></pre>
  
  <p>Added binding in constructor to onChange (this was not there before), but this does not resolve the problem.
  this.onChange = this.onChange.bind(this);</p>
  
  <p>I'm using: react: "^16.8.6"</p>
  
  <p>Here is the component code:</p>
  
  <pre class="lang-js prettyprint-override"><code>import React from "react";
  import { Form, Button } from "semantic-ui-react";
  import Validator from "validator";
  import InlineError from "../messages/InlineError"
  
  class LoginForm extends React.Component {
      constructor(props) {
          super(props);
          this.state = {
              data: {
                  email: "",
                  password: ""
              },
              loading: false,
              errors: {}
          };
          this.onChange = this.onChange.bind(this);
      }
  
      onChange = e =&gt; {
          this.setState({
              data: { ...this.state.data, [e.target.name]: e.target.value }
          });
      }
  
      onSubmit = () =&gt; {
          const errors = this.validate(this.state.data);
          this.setState = ({ errors });
      };
  
      validate = (data) =&gt; {
          const errors = {};
          if (!Validator.isEmail(data.email)) errors.email = "Invalid email."
          if (!data.password) errors.password = "Cannot be blank.";
  
          return errors;
      };
  
      render() {
          const { data, errors } = this.state;
          return (
              &lt;Form onSubmit={this.onSubmit}&gt;
                  &lt;Form.Field&gt;
                      &lt;label htmlFor="email"&gt;Email&lt;/label&gt;
                      &lt;input
                          type="email"
                          id="email"
                          name="email"
                          placeholder="me@example.com"
                          value={data.email}
                          onChange={this.onChange}
                      /&gt;
  
                  &lt;/Form.Field&gt;
                  {errors.email &amp;&amp; &lt;InlineError text={errors.email} /&gt;}
                  &lt;Form.Field&gt;
                      &lt;label htmlFor="password"&gt;Password&lt;/label&gt;
                      &lt;input
                          type="password"
                          id="password"
                          name="password"
                          placeholder="Enter your password"
                          value={data.password}
                          onChange={this.onChange}
                      /&gt;
                      {errors.password &amp;&amp; &lt;InlineError text={errors.password} /&gt;}
  
                  &lt;/Form.Field&gt;
  
                  &lt;Button primary&gt;Login&lt;/Button&gt;
              &lt;/Form&gt;
          );
      }
  }
  
  
  export default LoginForm;
  
  </code></pre>