我使用的是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>
);
}
答案 0 :(得分:0)
您无法在CustomComponent
方法中定义render()
。当您第一次开始输入输入时,这将导致您的组件失去焦点。
您是否在Redux配置中正确设置了reducer?