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

300
Visualizações
Why does `dangerouslySetInnerHTML` not execute the javascript in nextjs?

In my next js application i would like for a script tag to be loaded and some javascript to be executed. what i have in my next js component is as follow :-

typeof window !== 'undefined' ? <div data-id='text_div_for_testing_only' dangerouslySetInnerHTML={{ __html: product.description }}></div> : null

The contents of product.description is as follows :-

<script>alert("I am the richtextbox alert")</script>

What i see in the HTML is basically this

<script>alert("I am the richtextbox alert")</script>

Unfortunately, the javascript never gets executed. However, if i do the following :-

typeof window !== 'undefined' ? alert("ok alert me") : null

I do see an alert in the UI. So why does dangerouslySetInnerHTML not execute the javascript in nextjs ?

P.S. also can't use Script from nextjs as i'am using a lower version of nextjs.

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