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

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

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