Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: useWatch returning array with undefined #11921

Closed
1 task done
phantomcosmonaut opened this issue May 21, 2024 · 1 comment
Closed
1 task done

issue: useWatch returning array with undefined #11921

phantomcosmonaut opened this issue May 21, 2024 · 1 comment

Comments

@phantomcosmonaut
Copy link

Version Number

7.51.5 (latest)

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/unruffled-mcclintock-44t7mp

Steps to reproduce

  1. Click Add Foobar button
  2. Click Remove Foobar
  3. Result: Exception is thrown: Cannot read properties of undefined (reading 'color')

Expected behaviour

Actual: useWatch returns [undefined]
Expected: useWatch returns []

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
@phantomcosmonaut phantomcosmonaut changed the title issue: useWatch returning array with undefined May 21, 2024
@phantomcosmonaut phantomcosmonaut changed the title useWatch returning array with undefined issue: useWatch returning array with undefined May 21, 2024
@AmineBosnali
Copy link

AmineBosnali commented May 24, 2024

Hi @phantomcosmonaut , the previous code used {getValues(foobars.${i}).color} to access the color value of each foobar item, which resulted in errors. The correct approach is to use {getValues(foobars.${i}.color)}.
This ensures that the color value is accessed correctly from the foobars array.
{getValues('foobars.${i}.color')}

@react-hook-form react-hook-form locked and limited conversation to collaborators May 25, 2024
@bluebill1049 bluebill1049 converted this issue into discussion #11936 May 25, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants