UNPKG

react-ssr-utils

Version:

Several utilities to bootstrap and simplify any React SSR setup

26 lines (20 loc) 636 B
import * as React from 'react'; import { renderToNodeStream } from 'react-dom/server'; import { ReadableTagStream, Interpolation } from 'stream-tag'; import { isReactElement } from './utils'; type ReactInterpolation = | Interpolation | React.ReactNode; const renderReactTag = ( strings: TemplateStringsArray, ...reactInter: ReactInterpolation[] ) => { const interpolations: Interpolation[] = reactInter.map(i => { if (isReactElement(i)) { return renderToNodeStream(i); } return i; }); return new ReadableTagStream(strings, interpolations); }; export default renderReactTag;