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

99
Views
Adding event listners to a string and then converting it to an html/react element

I have a function that splits and checks for a word that matches the regex.. and if word found it add it in a span tag and style it then parse it using react parser..

const checkContent = (content) => {
    content = content.split(' ')
    let tag = '<p>'
    content.map(word => {
      if(word.match(regex))
        tag += ` <span className="taggedUser">${word}</span> `
      else
        tag += ' ' + word
    })
    tag += '</p>'
    return ( parse(`<div>${tag}</div>`))
  }

However i'm having difficulty trying to add an event listner to it like OnClick(). The only solution I've come up with is adding the listners by js via addEventListner(). My question is there any other way other than the above mentioned. Adding the listner directly to the span tag like this <span OnClick={handleClick} className="tagged">${word}</span> and then returning it?? Any ideas??

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Have you tried adding onClick=${} or onClick={} directly to the span on line 6? I don't think it will actually work and I believe if you are using parse like this, from a library, to parse a react component you will need to add listeners via addEventListener().

about 4 years ago · Juan Pablo Isaza Report
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!