styletron-server-legacy

Legacy package for 1.x styletron-server

Usage no npm install needed!

<script type="module">
  import styletronServerLegacy from 'https://cdn.skypack.dev/styletron-server-legacy';
</script>

README

styletron-server

build status dependencies status npm version

A server-rendering helper module for styletron

Usage

Extracting "injected" CSS at render-time on the server

const styletronServer = require('styletron-server');

const renderApp = function mockRenderFn() {
  /**
   * `renderApp` is some function that renders your app, returning a string of HTML. 
   * This function should also result in `injectOnce` being called at some point.
   */
};

const {html, css, hydrationSrc} = styletronServer.renderStatic(() => {
  const html = renderApp();
  return html;
}

/**
 * `html` is simply the return value of the function passed into `renderStatic`.
 * It is passed through for convenience.
 */

/**
 * `css` is a string containing all CSS that was that injected into the buffer
 * during the render.
 */

/**
 * `hydrationSrc` is a string of JS source code to hydrate styletron on the client.
 * This script injects a <style> element containing the server-rendered styles and also 
 * prevents re-injection of server-rendered styles on subsequent client renders.
 * Set this string as the contents of a <script> element in <head> so it is before <body>
 * and your client bundle.
 */