react icon indicating copy to clipboard operation
react copied to clipboard

generateHydrationScript for React?

Open jaxramus opened this issue 1 year ago • 0 comments

In SolidJS for SSR you can use something called generateHydrationScript:

import { generateHydrationScript } from "solid-js/web";

const app = renderToString(() => <App />);

const html = `
  <html lang="en">
    <head>
      <title>🔥 Solid SSR 🔥</title>
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <link rel="stylesheet" href="/styles.css" />
      ${generateHydrationScript()}
    </head>
    <body>${app}</body>
  </html>
`;

What this does is it will automatically inject the necessary hydration script into the page so you don't have to worry about hydrating stuff in client-side scripts.

Is there anything out there like this for React?

jaxramus avatar Jul 16 '22 03:07 jaxramus