title: setState from an API response using superagent and React
body: <p>I get an error when trying to change the state of a component.</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'setState' of undefined</p>
  </blockquote>
  
  <pre><code>constructor(props){
      super(props);
  
      this.state={
          r:'',
          message:''
      };
      this.setStateMessage = this.setStateMessage.bind(this);
  }
  setStateMessage (e){
      e.preventDefault();
      var test = this.state.message;
  
      request
        .post('http://127.0.0.1:5000/api/db')
        .send({message: this.state.message})
        .accept('application/json')
        .withCredentials()
        .end(function(err, res){
          if(err)
              throw err;
          this.setState({ r: res.body.message });
        });
  }
  
  render() {
      return (
          &lt;div&gt;
              &lt;div className='response'&gt;
                  {this.state.r}
              &lt;/div&gt;
              //form with input
          &lt;/div&gt;
      )}
  </code></pre>