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

76
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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