Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!