我使用的是redux-form,在添加initialize
方法和componentDidUpdate()
之后,我无法在输入内输入内容。当我尝试输入我的电子邮件时,不会出现任何字符。我猜所有的输入都被控制了?如果是的话,我将如何处理?为什么我不能输入我的字段?
import { reduxForm, Field, initialize } from 'redux-form';
const CustomComponent = function(field) {
return(
<div>
<input { ...field.input } type={field.type} placeholder={field.placeholder} />
</div>
);
}
//class instantiation
componentDidUpdate(){
this.handleInitialize();
}
handleInitialize() {
const initData = {
"name": this.props.name
};
this.props.initialize(initData);
}
render() {
const { handleSubmit } = this.props;
return (
<div>
<form onSubmit={handleSubmit(this.onSubmit)}>
<div>
<Field name="name" component={CustomComponent} type="text" placeholder="Name" />
<Field name="email" component={CustomComponent} type="email" placeholder="Email" />
</div>
<button type="submit">Submit</button>
</form>
</div>
);
}
您是否尝试在CustomComponent中返回没有div包装的输入? – Andrew
这不起作用。同一问题 – joethemow
@MarkFitzgerald您发布的问题的答案不适用,因为我在发布问题之前已经实施了该问题。 – joethemow