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

114
Visualizações
Render MUI components to string client side?

I am using the Material UI (MUI) library as a basis for my React app and I am trying to render some of the components to PDF in the browser.

The strategy is:

  1. Create a React element
  2. Render the React element to an HTML string
  3. Render the HTML string as a PDF

My code currently:

import React from "react";
import ReactDOMServer from 'react-dom/server';
import { ThemeProvider, createTheme } from "@mui/material/styles";
import { jsPDF } from "jspdf";

// ...

const el = (
  <ThemeProvider theme={myTheme}>
    <CssBaseline />
    <App />
  </ThemeProvider>
);

const html = ReactDOMServer.renderToString(el);

const doc = new jsPDF({
  orientation: "portrait",
  unit: "px",
});

const callback = () => {
  doc.save("test.pdf");
};

doc.html(html, { callback });

However, this does not render the theme correctly (fonts, background colors, etc). I believe this is an issue with step (2).

MUI uses Emotion for CSS styling, but the SSR packages for Emotion only seem to work on Node.

import { renderStylesToString } from '@emotion/server';

How can I render the styles into a complete HTML string in the browser?


Some versions:

"react": "^17.0.2",
"@mui/material": "^5.0.0",
"@emotion/css": "^11.7.1",
about 4 years ago · Juan Pablo Isaza
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