redux在输入字段中形成自定义值

时间:2017-06-09 18:45:30

标签: reactjs redux redux-form

我尝试将自定义输入值传递到字段中,我已经使用了initialValue或dispatch change,但我想完全保留我的对象,但只显示一个值。

例如:

const value = { name:'bob', firstname:'lanvin', age:28 }

    <Field component={MyCustomInput} val="value.name"/>

    const MyCustomInput = (props, value) => {
      return (
        <div class="input-row">
          <input type="text" {...props} defaultValue="val"/>
          {props.touched && props.error && <span className="error">{props.error}</span>}
        </div>
      )
    }/>

我在某个页面重复这个字段,所以我想显示一个时间名称和年龄之后,...这是最好的方法吗?

1 个答案:

答案 0 :(得分:0)

该值将作为组件的支柱提供。您可以像

一样处理它
const value = { name:'bob', firstname:'lanvin', age:28 }

<Field component={MyCustomInput} val={value.name}/>

const MyCustomInput = (props) => {
  return (
    <div class="input-row">
      <input type="text" {...props} defaultValue={props.val}/>
      {props.touched && props.error && <span className="error">{props.error}</span>}
    </div>
  )
}/>
相关问题