0
错误为什么错误与validate函数一起定义?我在日志中打印错误,但在字段中未定义。当我尝试做field.meta.error时,我得到一个未定义的。我把它放在<input>
之后的inputComponent常数中。Redux窗体错误未定义
const inputComponent = function(field) {
return (
<div>
<input { ...field.input } type={field.type} placeholder={field.placeholder} className={field.className} />
</div>
);
}
class Test extends Component {
render() {
<div>
<Field name="name" component={inputComponent} type="email" placeholder="Email" />
<Field name="password" component={inputComponent} type="password" placeholder="Password" />
</div>
}
function validate(values) {
const errors = {};
if(!values.name) {
errors.categories = "Name error";
}
if(!values.password) {
errors.categories = "Password error";
}
return errors;
}
}
Test = reduxForm({
form: 'NameForm',
validate
}, null, null)(Test);
export default connect(mapStateToProps, mapDispatchToProps)(Test);