title: Redux-form - Redirect after server response
body: <p>I am using redux-form in react and I would like to redirect to other page after succesful server response ( res 200) . Here is full code with my class LoginForm:</p>
  
  <pre><code>class LoginForm extends React.Component {
  
    state = {
        redirectToNewPage: false
      }
  
    handleSubmit=({email='',password=''})=&gt;{
      let error={};
      let isError=false;
      if(email.trim()===''){
        error.email='Required';
        isError=true;
      }   
      if(password.trim()===''){
        error.password='Required';
        isError=true;
      }
      if(isError){
        throw new SubmissionError(error);
        }
      else{
          //this.setState({ redirectToNewPage: true });  // &lt;--- it will redirect
          fetch('/auth', {
            method: 'POST',
            headers: {
              'Accept': 'application/json',
              'Content-Type': 'application/json',
            },
            body: JSON.stringify({
              email: email,
              password: password,
            })
          })
          .then( function(res){
            console.log(res.status);
            if(res.status==200){
              console.log("REDIRECTING...");
              //this.setState({ redirectToNewPage: true }); // It will show error unknow function
  
            }
            else{
              console.log("ERROR");
            }
          })
  
  
        }
    }
  
    static propTypes={
      handleSubmit:React.PropTypes.func
    }
  
      render(){
        const {handleSubmit}=this.props;
        if (this.state.redirectToNewPage) {
         return (
                 &lt;Redirect to="/markers"/&gt;
         )
        }
        return(
          &lt;div className="container"&gt;
        &lt;form className="form-login" onSubmit={handleSubmit(this.handleSubmit)}&gt;
          &lt;h2 className="form-login-heading"&gt;Login&lt;/h2&gt;
            &lt;Field name="email"  label="Email address"  component={renderField} type="email" placeholder="Email"/&gt;
            &lt;Field name="password"  label="Password"  component={renderField} type="password" placeholder="Password"/&gt;
          &lt;button className="btn btn-lg btn-primary btn-block" type="submit"&gt;Login&lt;/button&gt;
        &lt;/form&gt;
        &lt;/div&gt;
      )
  }
  
  };
  </code></pre>
  
  <p>The problem is inside handleSubmit method. I can't use (this.setState()) inside .then after fetch:</p>
  
  <pre><code>.then( function(res){
            console.log(res.status);
            if(res.status==200){
              console.log("REDIRECTING...");
              //this.setState({ redirectToNewPage: true }); // It will show error unknow function
  
            }
            else{
              console.log("ERROR");
            }
  </code></pre>
  
  <p>I got an error :</p>
  
  <blockquote>
    <p>Uncaught (in promise) TypeError: Cannot read property 'setState' of
    undefined</p>
  </blockquote>
  
  <p>Have you got any ideas how to do that?</p>