【问题标题】:How to make a custom redux-form component control multiple fields?如何让自定义的 redux-form 组件控制多个字段?
【发布时间】:2017-07-09 20:16:25
【问题描述】:

我想要一个带有可拖动标记的Map,该标记确定xy 字段。

<Fields names={['x', 'y']} component={Map} />

当标记被放到地图上的新位置时,我如何告诉 redux-form 新的 xy 值是什么?

http://redux-form.com/6.5.0/docs/faq/CustomComponent.md/

【问题讨论】:

  • 根据redux-form.com/6.5.0/docs/api/Field.md,组件可以是 Component|Function|String [必需]。仍然不清楚您所说的 singleMap 组件是什么意思。
  • 感谢@SherinMathew,为了清楚起见,我已经编辑了问题
  • this.props.onChange({ x, y }) ?你不能只存储一个对象作为值吗?
  • 不这么认为——它与现有的具有平面值的 API 挂钩

标签: redux-form


【解决方案1】:
const renderMap = props => (
  <DragDrop
    image={props.image}
    currentValue={{
      x: props.x.input.value,
      y: props.y.input.value,
    }}
    thingsChanged={coords => {
      props.x.input.onChange(coords.x);
      props.y.input.onChange(coords.y);
    }} />
)

<Fields
  names={['x', 'y']}
  component={renderMap}
  image={this.state.image} />

【讨论】:

    猜你喜欢
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 2019-07-08
    相关资源
    最近更新 更多