-
Notifications
You must be signed in to change notification settings - Fork 48.6k
Provide a way to pass context to renderToStaticMarkup on the client #14292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Generally, using SSR methods on the client is discouraged. Instead, it's better to render into a DOM node and then read |
@gaearon what are the advantages of that approach? Does the browser provide some normalization or other advantage? |
It's unfortunate to bundle a whole server renderer on the page just to produce HTML since you can already produce HTML just with React DOM. Additionally, if you do it in your component, you still have the context etc, which is what the original complaint was about. |
@gaearon using What would be the best way to keep it simple to wait for the render? Should I use a function frontendRenderToStaticMarkup(component: JSX.Element): string {
const container = document.createElement('div');
const root = createRoot(container);
root.render(component);
console.log(container.innerHTML);
console.log(container.outerHTML);
const html = container.innerHTML;
console.log(container);
console.log(html);
console.log(root);
// root.unmount();
return html;
} Thank you, EDIT: note in my case I don't want it to be displayed to the user, that's why I try to do things isolated. Maybe a solution would be to mount my component into the page while being In my case I just wanted to reuse the JSX templating with some context like translations to generate HTML to be put into the clipboard. EDIT2: I ended with a boolean state on the parent component to display the child, and within the child a |
See #14287 (comment) and #14182 (comment). This accidentally worked for a few releases but was a bug. However we might want to consider actually supporting this with an opt-in API.
The text was updated successfully, but these errors were encountered: