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

72
Views
React component does not call onClick handler

I have a component built with es6 class syntax. It's a simple component with just a diverse and some styling. Then, on the parent component (called app), I'd like to render that component and give it an onClick that calls the parent's onclick handler. So far, the parent renders the child like so:

<child_component onClick={this.clickhandler}>

And then I have a method in that parent component that I have bound to the parent's context in the constructor.

The component renders, but the click handler is never called when I click the component. Any idea why?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Since child componet isn't a native DOM element but, another React component, onClick as defined here is simply a property of that component. What you need to do is, inside of the child component pass the onClick prop to an DOM component's onClick event:

var ChildComponet= React.createClass({
 render: function() {
 return (
   <div className="childcomponent" onClick={this.props.onClick}>
   ...
    </div>
  );
 }
 });
over 4 years ago · Santiago Trujillo Report
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!