【问题标题】:Generate CSS for Server Side Rendering in React - Material-UI在 React 中为服务器端渲染生成 CSS - Material-UI
【发布时间】:2019-02-24 14:39:33
【问题描述】:

我正在尝试根据Material UI - Server Rendering为服务器端渲染生成 CSS

我将 React on Rails 与 PHP (React Bundle) 一起使用,还有其他生成 CSS 的方法吗?在文档中,我们在 JS 中的一个请求中提供所有完整内容。在我的情况下,我必须为 twig 和下一个单独的 CSS 提供组件。还有其他方法吗?

【问题讨论】:

    标签: php css reactjs symfony server-side-rendering


    【解决方案1】:

    我想你可以将带有 html 模板的 CSS 传递给客户端,就像我在我的一个项目中所做的一样。

    const cssStyleTage = extractCSSFromMaterialUIServerSideAPI();
    const componentStream = someHtmlConten;
    
    const html = `
      <!doctype html>
        <html>
        <head>
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          ${cssStyleTage}
        </head>
        <body>
            <div id="root">
                ${componentStream}
            </div>
        </body>
        </html>`;
    
    // pass it to client, this you can open in any iframe at client side.
    res.status(200).send(html);
    
    // or otherwise just send the css styles separately.
    res.status(200).send({
      cssStyleTags: cssStyleTage,
      html: componentStream
    });
    

    我只是想知道有哪些可能的方法可以完成,如果这可以帮助您完成任务。

    【讨论】:

      猜你喜欢
      • 2020-10-01
      • 1970-01-01
      • 2018-05-18
      • 2020-01-27
      • 2016-04-09
      • 2017-05-26
      • 2021-06-18
      • 1970-01-01
      • 2015-05-07
      相关资源
      最近更新 更多