Repository navigation
fix(react-hook-form): useFieldArray fields empty on second visit - #7417
zons-zhaozhy wants to merge 1 commit into
Conversation
|
|
Hello @zons-zhaozhy please see if any additional tests are needed. Also you need to create changeset for us to release the fix. Please see details here: https://refine.dev/core/docs/guides-concepts/contributing/ |
|
Hi, there's already a PR open for this issue: #7402. Do you see any problems with its implementation? If so, let's discuss there instead of creating additional PRs! |
Hey! Saw #7401 and figured I'd take a look.
The issue is that
applyValuesToFields(getRegisteredFields(), data, false)missesuseFieldArrayfields when navigating back to the edit form. The problem: on the second visit, fieldArray fields register after thequeueMicrotaskcallback runs, sogetRegisteredFields()doesn't include them.The fix replaces the manual
setValueloop with RHF'sreset(data, { keepDirtyValues: true }).resethandles field arrays natively and doesn't depend on field registration timing.Changes:
resetto the destructuring fromuseHookFormResultapplyValuesToFields(getRegisteredFields(), data, false)withreset(data, { keepDirtyValues: true })This matches the fix suggested in the issue. Let me know if anything needs tweaking.