当我尝试将动作传递给reduxForm调用时,它不会将动作映射到道具。我收到此错误:

javascript - Redux-form matchDispatchToProps无法正常工作-LMLPHP
我在下面包括了错误重现的步骤。非常感谢您的帮助!

我的带有Redux-thunk的Test Action Creator

export function signUpUser({ firstName, lastName, email, password, passwordConfirm }) {
  console.log("action: ", firstName)
  console.log("action: ", lastName)
  console.log("action: ", email)
  console.log("action: ", password)
  console.log("action: ", passwordConfirm)
  return function(dispatch) {
        dispatch({
      type: AUTH_USER,
      payload: response.data.message
    });
    }
}


VSCode方法签名助手

(alias) reduxForm(config: ReduxFormConfig, mapStateToProps?: MapStateToProps, mapDispatchToProps?: MapDispatchToPropsFunction | MapDispatchToPropsObject): ClassDecorator
import reduxForm


我对reduxForm的呼叫

import { Field, reduxForm } from 'redux-form';
...
export default reduxForm({
  form: 'authentication'
}, null, signUpUser)(Login);


我在React.Component中的动作用法

handleFormSubmit(values) {
    this.validateFields(values);

    console.log("works")
    if (this.state.errors.email.exists && this.state.errors.email.valid && this.state.errors.password.match) {
      console.log("works2")
      this.props.signUpUser(values);
    }
  }

最佳答案

如果@Jyothi的注释对您不起作用,则您可能正在使用redux-form v6。在版本6中,您必须使用自己的redux-form connect ion,如下所示。

class MyForm extends Component {}
MyForm = reduxForm(config)(MyForm)
MyForm = connect(mapStateToProps, mapDispatchToProps)(MyForm)
export default MyForm


这是redux-form文档中的example

09-07 16:31