1.7.0 • Published 5 years ago

second-renderer v1.7.0

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

Second Renderer

Installation

npm install --save second-renderer

Quick start

Render a React component

const Renderer = require('second-renderer')
const React = require('react')
const ReactDOMServer = require('react-dom/server')
const MyComponent = require('./my-react-component')

const renderer = new Renderer({
  VDom: React,
  VDomServer: ReactDOMServer
})

const markup = renderer.render(MyComponent)
const staticMarkup = renderer.renderStatic(MyComponent)

Combine with second-fetcher to create a container component

const Renderer = require('second-renderer')
const React = require('react')
const ReactDOMServer = require('react-dom/server')
const MyComponent = require('./my-react-component')

const renderer = new Renderer({
  VDom: React,
  VDomServer: ReactDOMServer
})

API

new Renderer({ VDom, VDomServer, ?componentIsReady }) -> Renderer

Constructs a new renderer.

Options

  • VDom (Object): A virtual DOM library that implements the createElement function. Examples are React and Preact.
  • VDomServer (Object): A virtual DOM library that implements the renderToString and (optionally) renderToStaticMarkup functions.
  • componentIsReady (Function -> Boolean): Optional. A function that determines whether rendered components are ready. When this function returns false, the renderer will continue to re-render the component after a short delay until the function returns true. This is often used in conjunction with second-fetcher to ensure all data has been fetched for the component before returning the rendered markup.

render(Component, props) -> Promise<string>

Renders a component to HTML, returning a Promise that resolves to a string containing the rendered HTML.

Arguments

  • Component (Object): A component object that can be rendered by the VDOM library's renderToString function.
  • props (Object): Props that are passed directly to the component.

renderStatic(Component, props) -> Promise<string>

Same as above but uses the VDOM library's renderToStaticMarkup function.

1.7.0

5 years ago

1.6.0

6 years ago

1.5.2

6 years ago

1.5.1

7 years ago

1.2.3

7 years ago

1.2.0

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago