setValue of parent to affect child field #12887
Unanswered
ryan-mardiono-sal
asked this question in
Q&A
Replies: 2 comments
-
You're correct in your analysis! This relates to how React Hook Form's Controller handles nested field updates.
An alternative solution is to reset the form like so
|
Beta Was this translation helpful? Give feedback.
0 replies
-
You'll run into issues with One option is to ensure that your function Suburb() {
const suburb = useWatch({ name: "suburb" });
if (suburb) {
return (
<SuburbId />
<SuburbText />
);
} else {
// Render something different if suburb is null
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey wondering if there is an option for my usecase, or if this goes against the react-hook-form rules.
I have a form with a field:
suburb: { id: 1, text: "test" }
Then I have a component using the Controller
<FormTextBox name="suburb.text"/>
.If I setValue("suburb.text", ""), then this will make it empty, but if I set setValue("suburb", null), this doesn't change the value field that the controller receives to null, it just keeps its previous value.
My TextBox component also does support input={inputValue ?? ""}. So I believe this is just due to the Controller renderer not detecting the field update due to registering against the suburb.text rather than suburb.
What could I do here to keep this same method? Thanks
Beta Was this translation helpful? Give feedback.
All reactions