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
In my use case, I have a large dynamic form divided into various tabs. When the user adds a field into a specific tab, the other tabs will need to add that field as well. At present, I’m accomplishing this by using setValue in a loop.
// Form.tsx
const form = useForm({
mode: 'all',
defaultValues: {tabs: []},
})
useEffect(() => {
const { unsubscribe } = watch(formData => {
// => this called multiple time
})
return () => {
unsubscribe()
}
}, [watch])
// FormSync.tsx
tabsNeedToModifiy.forEach(tab => {
const modifiedTab = {} // do some mutation
setValue(`tab.${index}`, modifiedTab)
})
Problem
However, this approach leads to multiple calls to the form.watch callback
Is there an alternative method that allows me to assign values to multiple form fields while only triggering a single form.watch callback?
What I found so far
I have looked around and saw this issue, I would love to see it to be implement since it would be helpful in my case
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.
-
Introduction
In my use case, I have a large dynamic form divided into various tabs. When the user adds a field into a specific tab, the other tabs will need to add that field as well. At present, I’m accomplishing this by using
setValue
in a loop.Problem
However, this approach leads to multiple calls to the
form.watch
callbackIs there an alternative method that allows me to assign values to multiple form fields while only triggering a single
form.watch
callback?What I found so far
I have looked around and saw this issue, I would love to see it to be implement since it would be helpful in my case
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions