Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

65
Views
Prevent watched field being triggered on setValue

I have 3 field that are being watched

const watchAmount = watch('amount')

const watchRate = watch('rate')

const watchTotal = watch('total')

Also, for each pair of watched field I have one useEffect

useEffect(() => {
  const [rawAmount, rawRate] = getValues(['amount', 'rate'])

  // ...

  setValue('total', total, { shouldTouch: false })
}, [watchAmount, watchRate])

useEffect(() => {
  const [rawRate, rawTotal] = getValues(['rate', 'total'])

  // ...

  setValue('amount', amount, { shouldTouch: false })
}, [watchRate, watchTotal])

useEffect(() => {
  const [rawAmount, rawTotal] = getValues(['amount', 'total'])

  // ...

  setValue('rate', rate, { shouldTouch: false })
}, [watchAmount, watchTotal])

When the user fill the first field (anyone of them), everithing is ok, the problem is: After one field populated, when the user is going to fill the second, because the cyclic dependency of the others watched variables, the events are dispatched and called so many times, because is like the user filling the form

Even with shouldTouch set to false the behavior happens.

Is there some way to fill the values of the fields without triggering the event?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!