Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

66
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda