title: How to call callback function after dispatch action Redux
body: <p>I use React Redux and I create a function to login, but I need to get a callback return after successfull login and redirect user to a page.</p>
  
  <p>I try to passing function as parameter but not working.</p>
  
  <p>How can I get the return after dispatch action?</p>
  
  <blockquote>
  <pre><code>Login fun
  </code></pre>
  </blockquote>
  
  <pre><code>export const login = (request,cb) =&gt; {
             return dispatch =&gt; {
                  let url = "/api/user/login";
                  axios({
                      method: "post",
                      url: url,
                      data: request,
                      config: { headers: { "Content-Type": "multipart/form-data" } }
                  })
                      .then(response =&gt; {
                          let authState = {
                              isLoggedIn: true,
                              user: response.data
                          };
                          cb();
                          window.localStorage["authState"] = JSON.stringify(authState);
                          return dispatch({
                              type: "USER_LOGIN_FULFILLED",
                              payload: { userAuthData: response.data }
                          });
                      })
                      .catch(err =&gt; {
                          return dispatch({
                              type: "USER_LOGIN_REJECTED",
                              payload: err
                          });
                      });
             };
      };
  </code></pre>
  
  <blockquote>
    <p>submiting</p>
  </blockquote>
  
  <pre><code>handleLogin(e) {
          this.setState({ showLoader: true });
          e.preventDefault();
          const request = new Object();
          if (this.validator.allValid()) {
              request.email = this.state.email;
              request.password = this.state.password;
              this.props.login(request, () =&gt; {
                  //get callbach here
                  this.props.history.push('/my-space/my_views');
              })
  
              this.setState({ showLoader: false });
  
          } else {
              this.setState({ showLoader: false });
              this.validator.showMessages();
              this.forceUpdate();
          }
      }
  const mapStateToProps = state =&gt; {
      return {
          authState: state
      };
  };
  const mapDispatchToProps = dispatch =&gt; {
      return {
          login: request =&gt; dispatch(login(request))
      };
  };
  export default connect(mapStateToProps, mapDispatchToProps)(LoginForm);
  </code></pre>