Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda