How to use the emotion-server.renderStylesToString function in emotion-server

To help you get started, we’ve selected a few emotion-server 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 c8r / x0 / lib / build.js View on Github external
let html
  let css
  switch (cssLibrary) {
    case 'styled-components':
      const { ServerStyleSheet } = require('styled-components')
      const sheet = new ServerStyleSheet()
      html = render(
        sheet.collectStyles(
          React.createElement(App.default, { routes, path })
        )
      )
      css = sheet.getStyleTags()
      return { path, html, css, props }
    case 'emotion':
      const { renderStylesToString } = require('emotion-server')
      html = renderStylesToString(
        render(app)
      )
      return { path, html, props }
    case 'glamor':
      // doesn't seem to be working...
      const glamor = require('glamor/server')
      const res = glamor.renderStatic(() => (
        render(app)
      ))
      html = res.html
      css = `<style>${res.css}</style>`
      return { path, html, css, props }
    default:
      html = render(app)
      return { path, html, props }
  }
github contentz-tech / contentz / src / lib / render-archive.js View on Github external
caches.reduce((prev, next) =&gt; next === prev, true) &amp;&amp;
    (await checkCache("config.yml", JSON.stringify(config)))
  ) {
    return true;
  }

  const messages = await i18n();

  try {
    const links = articles.map(article =&gt; formatURL(article.path));
    const metadatas = articles.map(article =&gt; ({
      path: article.path,
      ...getMeta(article).data
    }));

    const html = renderStylesToString(
      ReactDOMServer.renderToStaticMarkup(
        jsx(
          IntlProvider,
          { locale: config.language || config.lang || "en", messages },
          jsx(
            Document,
            { config, links, path: "./articles.mdx" },
            jsx(ArchivePage, { config, articles: metadatas })
          )
        )
      )
    );
    await writeContent(`${html}`);
  } finally {
    console.log("Render completed: Archive");
  }
github contentz-tech / contentz / src / lib / render-home.js View on Github external
async function render(config) {
  if (await checkCache("config.yml", JSON.stringify(config))) return true;
  const messages = await i18n();
  try {
    const html = renderStylesToString(
      ReactDOMServer.renderToStaticMarkup(
        jsx(
          IntlProvider,
          { locale: config.language || config.lang || "en", messages },
          jsx(
            Document,
            { config, messages, path: "home.mdx" },
            jsx(HomePage, { config, messages })
          )
        )
      )
    );
    await writeContent(`${html}`);
  } finally {
    console.log("Render completed: Home");
  }
github fannypackui / fannypack / packages / website / gatsby-ssr.js View on Github external
export const replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
  const html = renderStylesToString(renderToString(bodyComponent));
  replaceBodyHTMLString(html);
};
github mui-org / material-ui / packages / material-ui-benchmark / src / styles.js View on Github external
.add('EmotionServerCssButton', () =&gt; {
    renderStylesToString(
      ReactDOMServer.renderToString(
        
          {Array.from(new Array(5)).map((_, index) =&gt; (
            Material-UI
          ))}
        ,
      ),
    );
  })
  .add('Naked', () =&gt; {
github contentz-tech / contentz / src / lib / render-error.js View on Github external
async function render(config) {
  if (!(await exists("./public/404.html"))) {
    const messages = await i18n();
    try {
      const html = renderStylesToString(
        ReactDOMServer.renderToStaticMarkup(
          jsx(
            IntlProvider,
            { locale: config.language || config.lang || "en", messages },
            jsx(
              Document,
              {
                config,
                path: "error.mdx",
                data: {
                  title: messages.error.title,
                  description: messages.error.description
                }
              },
              jsx(ErrorPage, { config })
            )
github cds-snc / security-goals / web-report / src / server.js View on Github external
.get("/*", (req, res) =&gt; {
    const context = {};
    const markup = renderStylesToString(renderToString(
      
        
      
    ));

    if (context.url) {
      res.redirect(context.url);
    } else {
      res.status(200).send(
        `
    
    
        
        
        <title>Security Goals Web Report</title>
github everydayhero / constructicon / source / lib / renderDocument / index.js View on Github external
assets,
  content = '',
  state = {},
  DocumentComponent = Document
}) =&gt; {
  const styles = assets.filter(asset =&gt; asset.match(/\.css$/))
  const scripts = assets.filter(asset =&gt; asset.match(/\.js$/))

  return (
    '' +
    renderToStaticMarkup(
      createElement(DocumentComponent, {
        head: Helmet.rewind(),
        styles,
        scripts,
        content: renderStylesToString(content || ''),
        state
      })
    )
  )
}
github mathdroid / mathdro.id / static.config.js View on Github external
  renderToHtml: (render, Comp) =&gt; renderStylesToString(render()),
  getSiteData: () =&gt; ({
github reakit / reakit / packages / website / gatsby-ssr.js View on Github external
export const replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
  const html = renderStylesToString(renderToString(bodyComponent));
  replaceBodyHTMLString(html);
};

emotion-server

Extract and inline critical css with emotion for server side rendering.

MIT
Latest version published 4 years ago

Package Health Score

72 / 100
Full package analysis