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

182
Vistas
Using onChange vs onClick in custom components

I'm writing a simple custom component (fancy toggle switch, fwiw) and I'm curious what opinions are about using both an onChange prop and an onClick prop. I'm currently using both to facilitate a separate confirmation modal that attaches to the onClick property.

Example:

     if (onClick !== undefined) onClick({ checked: !isChecked })
     if (onChange !== undefined) {
       onChange(!isChecked)
       setUncontrolledChecked(!isChecked)
     } else setUncontrolledChecked(!isChecked)

In this case, onClick works to circumvent the change in the toggle and allow the component to act as fully controlled, while the onChange hooks in to allow for side effects where the component is being used in an uncontrolled way elsewhere in the application.

Probably this topic is covered in some official designation of component properties somewhere, but I haven't been able to find it, so I'm interested to hear what SO thinks.

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