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

101
Visualizações
React can't fire onClick

All the events on the Article: onMouseMove, onMouseDown etc. are correctly executed. But onClick don't. I can see the button but clicking in it nothing happens.

Button showed

const onDelete = () => {
  console.log('delete')
};

return (
  <>
    {show &&
      <Ul style={{top: pos.y, left: pos.x}}>
        <Li>
          <Button onClick={onDelete}>
            <Trash /> Delete
          </Button>
        </Li>
      </Ul>
    }
    <Article ref={ref} onContextMenu={onRightClick}
      onMouseMove={onMouseMove} onMouseDown={onMouseDown} onMouseUp={onMouseUp} onMouseLeave={onMouseLeave}
    >
      {children}
    </Article>
  </>
);

If I move the code in brackets to inside Article, onClick is fired but the style of Ul doesn't work properly. I have other components that execute events correctly being inside brackets. But for some reason this component only executes the events in the Article.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I found the answer. I had another function that closes that button when I click outside the button (using ref). But when I clicked in button that function was fired because I was using same ref. I just had to use another ref and worked!!!

useClickOutside(ref2, () => setShow(false));

const onDelete = () => {
  console.log("delete");
};

return (
  <>
    {show &&
      <Ul style={{top: pos.y, left: pos.x}}>
        <Li>
          <Button ref={ref2} onClick={onDelete}>
            <Trash /> Delete
          </Button>
        </Li>
      </Ul>
    }
    <Article ref={ref} onContextMenu={onRightClick}
      onMouseMove={onMouseMove} onMouseDown={onMouseDown} onMouseUp={onMouseUp} onMouseLeave={onMouseLeave}
    >
      {children}
    </Article>
  </>
);
about 4 years ago · Juan Pablo Isaza Relatório

0

Try this:

 onClick={() => onDelete()}
about 4 years ago · Juan Pablo Isaza 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