Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!