summaryrefslogtreecommitdiff
path: root/packages/renderers/renderer-react/server.js
blob: 3518f6447bd0d48aa5fcb1d9ffc9dadfdbf9852f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { createElement as h } from 'react';
import { renderToStaticMarkup as renderToString } from 'react-dom/server.js';
import StaticHtml from './static-html.js';

function check(Component, props, children) {
  try {
    const { html } = renderToStaticMarkup(Component, props, children)
    return Boolean(html)
  } catch (e) {}
  return false;
}

function renderToStaticMarkup(Component, props, children) {
  const html = renderToString(h(Component, { ...props, children: h(StaticHtml, { value: children }), innerHTML: children }));
  return { html };
}

export default {
  check,
  renderToStaticMarkup,
};