HLH
HLH

Reputation: 1167

In React Final Form, providing initialValues to nested fields

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.

Upvotes: 0

Views: 1045

Answers (1)

Erik R.
Erik R.

Reputation: 7272

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?

Upvotes: 2

Related Questions