Reactjs 未捕获的TypeError:dispatch(…)。then不是函数

Reactjs 未捕获的TypeError:dispatch(…)。then不是函数,reactjs,react-redux,react-thunk,Reactjs,React Redux,React Thunk,容器组件 import { connect } from 'react-redux'; import { signUpUser } from '../actions/userActions'; import Register from '../components/register'; function mapStateToProps(state) { return { user: state.user }; } const mapDispatchToProp

容器组件

import { connect } from 'react-redux';
import { signUpUser } from '../actions/userActions';

import Register from '../components/register';

function mapStateToProps(state) {
    return { 
      user: state.user
    };
}

const mapDispatchToProps = (dispatch, ownProps) => {
    return {

    }
}

export default connect(mapStateToProps, mapDispatchToProps)(Register);
登记表

import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router-dom';
import { reduxForm, Field, SubmissionError } from 'redux-form';
import { signUpUser } from '../actions/userActions';

//Client side validation
function validate(values) {
  var errors = {};
  var hasErrors = false;


  return hasErrors && errors;
}

//For any field errors upon submission (i.e. not instant check)
const validateAndSignUpUser = (values, dispatch) => {
    //console.log(values);
    return dispatch(signUpUser(values))
      .then((response) => {
      console.log(response);
    });
};


class SignUpForm extends Component {

  render() {
    const { handleSubmit } = this.props;
    return (
      <div className="col-md-6 col-md-offset-3">
        <h2>Register</h2>
        <form onSubmit={ handleSubmit(validateAndSignUpUser) }>
          <div className ='form-group'>
              <label htmlFor="firstname">Name</label>
              <Field name="firstname" type="text" component= "input"/>
          </div>
          <div className ='form-group'>
              <label htmlFor="username">Username</label>
              <Field name="username" type="text" component= "input"/>
          </div>
          <div className ='form-group'>
              <label htmlFor="password">Password</label>
              <Field name="password" type="text" component= "input"/>
          </div>
          <div className="form-group">
              <button className="btn btn-primary">Register</button>
              <Link to="/" className="btn btn-error"> Cancel </Link>
          </div>
      </form>
     </div>
    )
  }
}

export default reduxForm({
  form: 'SignUpForm', // a unique identifier for this form
  validate
})(SignUpForm)
当我提交这份表格时,我发现以下错误。 此应用程序使用thunk,在组合减速器中设置窗体减速器。 我哪里做错了?我是个新手

Uncaught TypeError: dispatch(...).then is not a function

dispatch的返回值是内部函数的返回值,在您的情况下,它是一个对象而不是承诺。() 您必须在操作中直接返回
axios.get(…)
(它基本上返回一个承诺),以便像在示例中一样调用dispatch的返回值
then()


我建议不要将注册请求放在单独的操作中,因为在redux表单的提交功能中更容易处理请求。否则,可能很难处理来自服务器的带有验证消息的响应。我还认为您不需要在任何其他地方重复使用该操作,对吗?如果您需要在注册后更改状态中的某些内容,只需创建另一个操作,如“SignedUpser”,并向其传递一些数据。

dispatch的返回值是内部函数的返回值,在您的情况下,它是一个对象而不是承诺。() 您必须在操作中直接返回
axios.get(…)
(它基本上返回一个承诺),以便像在示例中一样调用dispatch的返回值
then()

我建议不要将注册请求放在单独的操作中,因为在redux表单的提交功能中更容易处理请求。否则,可能很难处理来自服务器的带有验证消息的响应。我还认为您不需要在任何其他地方重复使用该操作,对吗?如果需要在注册后更改状态中的某些内容,只需创建另一个操作,如“SignedUpser”,并向其传递一些数据

Uncaught TypeError: dispatch(...).then is not a function