Skip to content

📡 A server-rendering helper module for styletron

License

Notifications You must be signed in to change notification settings

brendean/styletron-server

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.
 */

About

📡 A server-rendering helper module for styletron

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%