Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda