question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FieldArray inner fields not updating values after reset

See original GitHub issue

Please consider asking the question at our spectrum channel.

https://spectrum.chat/react-hook-form

Describe the question?

First of all, I wanted to thank you for creating this awesome library. I created a project a few months earlier, leave it there, and now that I came back to do some updates I’m amazed by the huge progress this library has made.

I’m not sure if this is a bug or it’s by design, and I couldn’t find any other issue for this specific problem.

When calling reset on the form to set a new state for the inputs, I’ve notice that the array field inputs doesn’t behave as any other regular input. Regular inputs update their value automatically, but for field arrays you have to use defaultValue={field.value} in order to get it to update. I was hoping those field could behave just as the rest would.

To Reproduce Steps to reproduce the behavior:

  1. Go to code sandbox
  2. Click on ‘reset values’ button

The field array get’s populated with two inputs, as defined by the object passed to reset, but their values are empty. The regular input outside the array works as expected.

Codesandbox link Include a codesandox will help us to investigate the issue quicker. https://codesandbox.io/s/field-array-not-loading-values-from-reset-sc3bx

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dariusz-acaicommented, Apr 4, 2020

Thank you for quick answer - right - it works, didn’t get that we were talking about ‘defaultValue’ in input field (focusing on defaultValue in useFrom()). Yet, I still having problem with my code and Material UI TextField component - trying to reproduce - I will post it today.

0reactions
bluebill1049commented, Apr 4, 2020

@dariusz-acai for questions please post at spectrum.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReduxForm - enableReinitialize doesn't update values in ...
This issue is in nested field array. When a new item is added reducers will update the state and initialize the fields and...
Read more >
API Reference
This will update the values[key] where key is the event-emitting input's name ... Increases when handleSubmit is called, resets after calling handleReset ....
Read more >
Managing nested forms gracefully with Formik - Rajesh Naroth
So we need to add some hooks to update the field's values. We will build a custom hook for that. import { isEmpty...
Read more >
Arrays | Elasticsearch Guide [8.5]
An empty array [] is treated as a missing field — a field with no values. Nothing needs to be pre-configured in order...
Read more >
useFieldArray
Important: update data is required and not partial. replace, (obj: object[]) => void, Replace the entire field array values.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found