问题描述
这个 react-final-form 组件会返回如下结果
<Field
name="answers[0].name"
component="input"
type="radio"
value="0"
/>
{ answers: [ { name: 'value' } ] }
{ answers: [ { name: 'user input value will here',other: 'my custom data' } ] }
解决方法
您可以向表单添加一个 initialValues
道具,该道具将预填充结果。
<Form
onSubmit={onSubmit}
initialValues={{
answers: [ { other: 'your custom data' } ]
}}
>
<Field
name="answers[0].name"
component="input"
type="text"
/>
</Form>