2017-02-21 87 views
1

我使用的是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

您是否尝试在CustomComponent中返回没有div包装的输入? – Andrew

+0

这不起作用。同一问题 – joethemow

+0

@MarkFitzgerald您发布的问题的答案不适用,因为我在发布问题之前已经实施了该问题。 – joethemow

回答

0

您不能在render()方法中定义您的CustomComponent。这会导致您的组件在首次开始输入输入时失去焦点。

您是否已在Redux配置中正确设置了减速器?

+0

我将CustomComponent移到了我的课外,但我仍然无法在我的字段中输入内容。 – joethemow

+0

我记录在我的componentDidUpdate里面,并且意识到每次我试图在字段中输入某些内容时都会调用它。我很确定这是问题。 – joethemow

相关问题