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

126
Visualizações
reactjs add event listener to server-side generated buttons

I have taken over a project, and looking at my current task, I can see that the html elements are generated from the backend and is rendered in react using dangerouslySetInnerHTML,

So basically, the backend generates a table of entries. my task is to add a button to it, so I added it in the backend.

My question is, how do I add an event listener to the buttons for each entries? What I've tried so far is giving all the buttons the same Id and adding value attribute with the entry's id as its value, and make an event listener inside useEffect, like this:

const handleClick = useCallback(event => {
    console.log(event);
})
useEffect(() => {
    let doc = document.getElementById('buttonId');
    doc.addEventListener('click', handleClick);
    
    return () => {
        doc.removeEventListener('click', handleClick);
    }

}, [handleClick]);

but the solution above doesn't seem to do anything, no errors or anything.

about 4 years ago · Santiago Trujillo
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