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

161
Vistas
React-hook-form custom onChange handler in checkbox -> change is not registered

I'd need to add custom handler in the onChange event of a checkbox, however, doing so onChange won't reflect to react-hook-form.

I've followed the instructions how to do custom onChange by following the chapter

Custom onChange, onBlur: ​ https://react-hook-form.com/api/useform/register/

However cannot make it work.

Seeing in the DevTool the first checkbox change reflects to form just fine however the latter with a custom handler does not.

...
const subscribeToNewsLetter = register('subscribeToNewsLetter')
...
<div>
  ​<label> I consent </label>
  ​<input            
    ​type="checkbox"
    ​{...register('consent')}  //This checkbox without any custom handler works fine
  ​/>
​</div>

​<div>
  ​<label>Subscribe to newsletter</label>
  ​<input            
    ​type="checkbox"
    ​onChange={(e) => {
      ​subscribeToNewsLetter.onChange(e); // This needs to do custom stuff in onChange
      ​handleChange(e);         // However doing so 
    ​}}                         // the change is not registered to hook-form
    ​onBlur={subscibeToNewLetter.onBlur}
    ​ref={subscibeToNewLetter.ref} 
  ​/>
</div>
...

I've been fiddling it here which illustrates the problem the best. https://stackblitz.com/edit/react-hook-form-fiddling-zlnhzs

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You've to update the input like that:

<input
  type="checkbox"
  {...subscibeToNewLetter}
  onChange={e => {
    subscibeToNewLetter.onChange(e);
    handleChange(e);
  }}
/>

👉🏻 https://stackblitz.com/edit/react-hook-form-fiddling-g3foaa

about 4 years ago · Juan Pablo Isaza Denunciar
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