react-hook-form: issue: Upgrading from 7.19.5 breaks watch API with useFieldsArray

Version Number

7.20.2

Codesandbox/Expo snack

N/A

Steps to reproduce

Sorry for missing repro link, I may try to dig into it later. I have a fields array containing selectable objects. Prior to 7.20.0, selecting a field would trigger re-render when using the watch() API. This stopped happening after 7.20.0.

Expected behaviour

watch() re-renders when field array changes

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project’s Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 24 (13 by maintainers)

Most upvoted comments

There’s a section on register method that mentions the dot vs bracket notation for field names. image

But, yeah, it doesn’t seem to be mentioned for the controller API (Controller / useController). Maybe it should be duplicated for the controller as well

Hey @bluebill1049! Good news, it seems one of the latest releases fixes this issue! 😃 I still don’t know what was causing it, but can’t reproduce it in 7.24.0 anymore. I tried on 7.20.4 last I think and it was still there, so something fixed it. Thank you!

I have improved the doc with what you suggested above @codelover2k please feel free to send us a PR next time.

https://github.com/react-hook-form/documentation

if you didn’t change the keyName then it’s the expected behavior, the previous version had unexpected behavior.

Is this the warning note about that? Screenshot 2021-11-25 at 11 56 19

If so, wouldn’t it be better to use something less generic and common as id? Something like rhf_id or something… I feel like 99% of datasets will have id as their default unique key, and thus will have the same issue if they miss this keyname collision, like I did.

Hi @mfferreira, I tried checking and my useFieldsArray() doesn’t lose IDs. However, I learned that I can use keyName to specify a different key which might come handy (?) Thank you!

@bluebill1049 Thanks for the quick reply! I am positive I was on 7.20.2, but I can have another go later. I tried to put together a simple example, but couldn’t reproduce it quickly, so it might be something more intricate