Redux-Form matchDispatchToProps 不工作
Redux-Form matchDispatchToProps not working
当我尝试将我的动作传递到 reduxForm 调用时,它不会将我的动作映射到道具。我收到此错误:
我在下面包含了错误重现的步骤。非常感谢您的帮助!
My Test Action Creator with redux-thunk
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。
当我尝试将我的动作传递到 reduxForm 调用时,它不会将我的动作映射到道具。我收到此错误:
My Test Action Creator with redux-thunk
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。