Necesitaría agregar un controlador personalizado en el evento onChange de una casilla de verificación, sin embargo, al hacerlo onChange no se reflejará en el formulario de gancho de reacción.
He seguido las instrucciones sobre cómo personalizar onChange siguiendo el capítulo
OnChange personalizado, onBlur : https://react-hook-form.com/api/useform/register/
Sin embargo, no puede hacer que funcione.
Al ver en DevTool, el primer cambio de casilla de verificación se refleja en forma muy bien, sin embargo, el último con un controlador personalizado no lo hace.
... 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> ...Lo he estado manipulando aquí, lo que ilustra mejor el problema. https://stackblitz.com/edit/react-hook-form-fiddling-zlnhzs
Tienes que actualizar la entrada así:
<input type="checkbox" {...subscibeToNewLetter} onChange={e => { subscibeToNewLetter.onChange(e); handleChange(e); }} />👉🏻 https://stackblitz.com/edit/react-hook-form-fiddling-g3foaa