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

152
Vistas
Parsing functions into dangerouslysetinnerhtml

I've currently go an issue with dangerouslysetinnerhtml. I'm trying to allow people to edit sections via a js document in react, and these edits appear in a form of a string. e.g. a person could parse the following as a string within the js file:

let html = `<div onClick="(input)=>{console.log(input)}">Click me</div>`

And in my code I'd like to display it as:

<div dangerouslySetInnerHTML={{ __html: html }}></div>;

The div appears just fine, but the 'onClick' function doesn't fire. I've seen recommendations to use HTML Parser, but that's not an option as I'm restricted from using external libraries in this case. Does anyone have any suggestions on how this should work?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do this way if you really need to.

let html = '<div onclick="console.log(this)">Click me</div>';

And same as you have done in your code.

<div dangerouslySetInnerHTML={{ __html: html }}></div>;
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