Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

67
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda