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

114
Vistas
React renderToString not rendering js

If I do

const clicked = () => console.log(“click”);

renderToString(<button onClick={clicked}>Click here</button>

and when I print out the rendered string, all I see is <button>Click here</button>

Is it possible that the JS is not rendered from this function?

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

0

renderToString() gives you your react app in pure HTML as it would look in a particular state. It does not give a fully functionaly react app.

The JS doc renderToString() says the following:

Render a React element to its initial HTML. This should only be used on the server. React will return an HTML string. You can use this method to generate HTML on the server and send the markup down on the initial request for faster page loads and to allow search engines to crawl your pages for SEO purposes.

If you call ReactDOM.render() on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.

What this means is that renderToString will never have event handlers in the output. It's meant for you to generate the raw HTML of a page in a particular state on the server, then react can rehydrate those elements will event handlers once loaded on the browser.

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