You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using react-hook-form, and if I use watch or useWatch returned by useFormContext, the value of the field changed in the child component is not reflected, but if I use useController, it is reflected. What is the difference between the two?
There is a function to remove items from an array using useFieldArray in a child component. However, there was a phenomenon in which the previous value was retained in the parent component after removal, so it was changed to after in the example.
before
const{ control }=useFormContext();const{ replace }=useFieldArray({name: 'confirmList',
control,});constconfirmList=useWatch({ control,name: 'confirmList'});
after
const{ control }=useFormContext();const{field: {value: confirmList},}=useController({name: 'confirmList', control });const{ replace }=useFieldArray({name: 'confirmList',
control,});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I am using react-hook-form, and if I use watch or useWatch returned by useFormContext, the value of the field changed in the child component is not reflected, but if I use useController, it is reflected. What is the difference between the two?
There is a function to remove items from an array using useFieldArray in a child component. However, there was a phenomenon in which the previous value was retained in the parent component after removal, so it was changed to after in the example.
before
after
Beta Was this translation helpful? Give feedback.
All reactions