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

270
Visualizações
Detect click from an html element outside a React app and a react component

I have an html page with:

  • html elements
  • some empty divs that will be replaced with react elements.

I would like to listen to a "click event" of an html element from a react component.

Here, i need to get inside the "react-component" an event that will be triggered when we click on the "click" element.

<div id="click">button in static html</div>
<div id="react-component"></div> -> replace by a react component

Is there a way to achieve that? Thanks

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

0

onClick event handler on any html tag will work in react

about 4 years ago · Juan Pablo Isaza Relatório

0

You can still write normal JS code in react. Just add a useEffect(..., []) hook and bind your buttons onClick using standard JS code in there.

Here is the documentation for the JS onclick event: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onclick

about 4 years ago · Juan Pablo Isaza Relatório

0

A few methods for this.
One of which is using querySelector or getElementById like you would in vanilla JS.

So you can do this:

// HTML:
<div id="click">button in static html</div>
<div id="react-component"></div> -> replace by a react component

// JSX:
const myElement = document.getElementById("click");
myElement.onclick = () => {
  ...
};
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