How to use the @material-ui/styles/ServerStyleSheets function in @material-ui/styles

To help you get started, we’ve selected a few @material-ui/styles examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thundermiracle / next-mui-helper / src / nextjs / extendsWithMui.js View on Github external
// 6. document.render
      //
      // On the server with error:
      // 1. document.getInitialProps
      // 2. app.render
      // 3. page.render
      // 4. document.render
      //
      // On the client
      // 1. app.getInitialProps
      // 2. page.getInitialProps
      // 3. app.render
      // 4. page.render

      // inject theme by hoc
      const sheets = new ServerStyleSheets();
      const originalRenderPage = ctx.renderPage;
      ctx.renderPage = () =>
        originalRenderPage({
          // wrap Jss context
          enhanceApp: App => props => sheets.collect(),
        });

      // get props after override the renderPage to get jss props
      const superProps = await super.getInitialProps(ctx);

      // push to head instead of override styles
      superProps.head.push(
        
          {sheets.getStyleElement()}
          {flush() || null}
        ,