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

179
Visualizações
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 à 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