In React Final Form, providing initialValues to nested fields

时光怂恿深爱的人放手 提交于 2020-01-03 05:28:11

问题


I'm working with React Final Form, and for some reason, when I try to pass initial values to its initialValues prop, it doesn't work if the keys I use are in the format 'key6.value' - the Field with that name stays empty. It does, however, work if the format doesn't have the . in the middle, e.g. 'key6value'.

Why doesn't initialValues work for these nested fields (fields with names that have the .)? And what can I do to make it pass the initialValues?

I've tested this thoroughly to make sure I identified the issue, and the only difference between having the Fields populate and not has been the . in their name attribute.


回答1:


You'll need to initialize with the actual nested structure. Not like this:

{
  'key5.value': 'init value' // ❌
  ...
}

Like this:

{
  key5: {
    value: 'init value' // ✅
  }
  ...
}

Does that help?



来源:https://stackoverflow.com/questions/52012228/in-react-final-form-providing-initialvalues-to-nested-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!