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

101
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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