Second Renderer
Installation
npm install --save second-renderer
Quick start
Render a React component
const Renderer = const React = const ReactDOMServer = const MyComponent = const renderer = VDom: React VDomServer: ReactDOMServer const markup = rendererconst staticMarkup = renderer
Combine with second-fetcher to create a container component
const Renderer = const React = const ReactDOMServer = const MyComponent = const 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 thecreateElement
function. Examples are React and Preact.VDomServer
(Object): A virtual DOM library that implements therenderToString
and (optionally)renderToStaticMarkup
functions.componentIsReady
(Function -> Boolean): Optional. A function that determines whether rendered components are ready. When this function returnsfalse
, the renderer will continue to re-render the component after a short delay until the function returnstrue
. 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'srenderToString
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.