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

295
Vistas
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 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