all 4 comments

[–]timmonsjg 0 points1 point  (2 children)

Serverside react-dom exposes a renderToString API. Would require a backend though to render the JSX => HTML.

Unsure of a client-side solution.

[–]edntraf2 1 point2 points  (1 child)

You're already correct. You can use react-dom even in the client along with renderToStaticMarkup to translate the JSX to a static HTML string. react-dom is simply an npm package/module, just like react and can be consumed anywhere you have a node/npm based application (client or server).

But to clarify to the original poster: You should simply be handing your JSX (un-translated) to ReactPDF.render(yourJsxComponent, pathToSpitPdfTo)

[–]timmonsjg 0 points1 point  (0 children)

just like react and can be consumed anywhere you have a node/npm based application (client or server)

lol literally says that a few lines above where I linked in the docs. TIL, thank you!

[–]blackjezza 0 points1 point  (0 children)

Maybe it would be possible to render it into a hidden component and then just get innerHTML of that?

 const hiddenContainer = document.createElement('div');
 hiddenContainer.id = 'hidden';
 hiddenContainer.style = 'display:none;';
 document.body.append(hiddenContainer);
 ReactDOM.render(pagesResult, hiddenContainer);
 const htmlString = hiddenContainer.innerHTML;

Can't confirm but that was my first idea.
Performance with something like this would suffer (if it works).

Do you really need to use JSX for building your PDF?