title: React making AJAX request in render without onClick trigger
body: <p>I have started yesterday to teach myself some React. I have a login form that is supposed to send a AJAX request to my backend when a button is clicked. This works, when I have my backend not running, meaning: My self written backend (tested with postman) has to be turned off so it does not reply and the page can render. 
  When it is running though the method gets called on render which is absolutely not desired as my backend sends an error and the page does not render.</p>
  
  <p>My react code is here: </p>
  
  <p>The Constructor: </p>
  
  <pre><code>constructor(props)
      {
          super(props);
  
          this.login                = this.login.bind(this);
          this.handleChangeUser     = this.handleChangeUser.bind(this);
          this.handleChangePassword = this.handleChangePassword.bind(this);
          this.logout = this.logout.bind(this);
  
          this.state = {
              user:     '',
              password: '',
              loggedIn: props.loggedIn
          };
      }
  </code></pre>
  
  <p>The Form: </p>
  
  <pre><code>return (
                  &lt;div&gt;
                      &lt;Navigation/&gt;
                      &lt;div style={{position: "relative", left: "30%", right: "70%"}}&gt;
                          &lt;label&gt;Username&lt;/label&gt;&lt;br/&gt;
                          &lt;input type={'text'} onChange={this.handleChangeUser} style={{width: "300px"}}/&gt;&lt;br/&gt;
                          &lt;label&gt;Password&lt;/label&gt;&lt;br/&gt;
                          &lt;input type={'password'} onChange={this.handleChangePassword} style={{width: "300px"}}/&gt;&lt;br/&gt;
                          &lt;div style={{width: "300px"}}&gt;
                              &lt;button type={"button"} className={"btn btn-primary"} style={{marginTop: "10px"}} onClick={this.login}&gt;
                                  Login
                              &lt;/button&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              );
  </code></pre>
  
  <p>And the login function that is causing all the trouble:</p>
  
  <pre><code>login(e)
      {
          e.preventDefault();
          axios({
              method: 'get',
              url:    BASE_URL + LOGIN,
              data:   {
                  user:     this.state.user,
                  password: this.state.password
              }
          }).then(function (result)
          {
              localStorage.setItem('botusToken', result.body.token);
              this.setState({loggedIn: true});
          }).catch(function ()
          {
              console.log("Error while login in");
          });
      }
  </code></pre>
  
  <p>This example works like a charm:</p>
  
  <pre><code>render()
      {
          return (
              &lt;div&gt;
                  &lt;form&gt;
                      &lt;label htmlFor="comment"&gt;Some comment&lt;/label&gt;
                      &lt;label htmlFor="triggerWord"&gt;Which trigger-word would you like your tweet to belong to?&lt;/label&gt;
                      &lt;select className={"form-control"} onChange={this.handleChangeSelector}&gt;
                          &lt;option&gt;Sad&lt;/option&gt;
                          &lt;option&gt;Fake News&lt;/option&gt;
                          &lt;option&gt;Taxes&lt;/option&gt;
                          &lt;option&gt;Immigrants&lt;/option&gt;
                          &lt;option&gt;Make America Great Again&lt;/option&gt;
                          &lt;option&gt;Make a new trigger word&lt;/option&gt;
                      &lt;/select&gt;
                      &lt;Textarea className={"form-control"} rows={2} cols={50} maxLength={140} wrap={"soft"}
                                onChange={this.handleChangeTextArea} value={this.state.tweet}/&gt;
                  &lt;/form&gt;
                  &lt;br/&gt;
                  &lt;button type={"button"} className={"btn btn-primary"} onClick={this.submitTweet}&gt;Submit&lt;/button&gt;
                  &lt;div style={errStyle}&gt;{this.state.err}&lt;/div&gt;
              &lt;/div&gt;
          );
      };
  </code></pre>
  
  <p>This method works like a charm in harmony with the form above:</p>
  
  <pre><code>submitTweet(e)
      {
          let self = this;
          e.preventDefault();
          let isNew = false;
          if (this.state.topic === "Make a new trigger word") isNew = true;
          axios({
              method: 'post',
              url:    BASE_URL + SUBMIT_TWEET,
              data:   {
                  topic: this.state.topic,
                  tweet: this.state.tweet,
                  new:   isNew
              }
          }).then(function ()
          {
              self.setState({err: ''});
          }).catch(function (err)
          {
              self.setState({err: "You have not entered all necessary information!"});
          });
  
          this.setState({tweet: ''});
  
      };
  </code></pre>
  
  <p>Thank you for taking a look!</p>