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.

getValues('fieldArray') doesn't seem to work inside of event handler

See original GitHub issue

Describe the bug When using useFieldArray, getValues('fieldArray') returns undefined inside of an event handler. But getValues().fieldArray returns the array though. 😅

To Reproduce Steps to reproduce the behavior:

  1. Click on ‘Append’.
  2. See log in the console.

Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-usefieldarray-template-forked-erbwu?file=/src/index.js:1575-1702

Expected behavior getValues('fieldArray') should returns the same thing as getValues().fieldArray.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
bluebill1049commented, Sep 24, 2020

@bluebill1049 Hm. I, by the way, also put “inline” defaultValue on each <Controller /> in my program, but it’s got the same inconsistency as illustrated in my CSB above (not sure if this is what you mean by “inline default value”). What makes it consistent in the end is to do defaulting values by using watch('test', fields) you mentioned above in my child component. 🤩

But then again, unfortunately I couldn’t achieve the same consistency when using useWatch({ name: 'test', control, defaultValue: fields }). 😕 Here, you can see what I mean by uncommenting the useWatch block: https://codesandbox.io/s/react-hook-form-usefieldarray-template-forked-do236?file=/src/Child.jsx:132-248

And yup - at the end of the day, probably this really needs some good explanation and tutorial 😁

I will take a look this useWatch inconsistency tmr.

2reactions
dwiyatcicommented, Sep 23, 2020

Sure! 😃 Would be glad to try to reconstruct this on CSB. I’ll work on it sometime this week~

Read more comments on GitHub >

github_iconTop Results From Across the Web

getValues('field') returns undefined combined with Form.List ...
When combining getValues and Form.List , getValues('names') returns undefined instead of the array itself. enter image description here.
Read more >
Using React Hook Form to Handle Field Array in a Modal Form
Using React Hook Form to Handle Field Array in a Modal Form#ionic #reacthookform #tutorialThis is a continuation of a previous video where I ......
Read more >
Form - Ant Design
High performance Form component with data scope management. Including data collection, verification, and styles. When to use.
Read more >
useFieldArray - Simple React forms validation
Performant, flexible and extensible forms with easy-to-use validation.
Read more >
No-Codifying Info and Error Messages - ServiceNow Community
Popups seem like one of those things that really shouldn't require a ... attach the same event handler script to each field on...
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