issue: useWatch / watch has wrong values when using form array with dnd kit #13513
Replies: 5 comments
|
Pretty sure it's related to this:
|
|
I see. Using Before: After: |
|
This PR may address this sort of issue #11522 as subscription can be established before react component. |
|
@bluebill1049 Can you explain how
Why does Is there any issues with doing something like this instead? |
|
I think adding a key to the <DragOverlay key={activeId}>
{activeId ? (
<FormRow {...getActiveChild()} isFromDragOverlay />
) : null}
</DragOverlay>Based on the code here, the overlay is indeed memo-ized and potentially the root cause.
In this instance, the previous active child continues to be rendered despite being moved. This lines up with your previous observation that the old values continue to persist there for some reason. It seems like this is likely due to dndkit and not react-hook-form. See the updated sandbox here. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Version Number
7.43.9
Codesandbox/Expo snack
Codesandbox reproduction
Steps to reproduce
There are two issues happening:
useWatchinGradeFieldreturnsundefinedvalue foradditionalInformationand renders the component, even thoughtype=== 'adult' and so that conditional field should be hidden completely.useWatchin top lvl component shows unexpected values (gradeproperty is now existing on both form rows, while it should only be existing for one row. The values in onSubmit are correct)It seems like either
useWatchruns earlier than expected or maybe there is a problem withkeys(due to how drag overlay works)Given that dnd kit react is widely used and they recommend using DragOverlay, it could be really helpful to have some examples / recommendations.
Thanks in advance 🙏
Expected behaviour
useWatchshould show proper values.useWatchshould not returnundefinedfor field which shouldn't even be rendered.What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
All reactions