summaryrefslogtreecommitdiff
path: root/packages/renderers/react/server.js
blob: aa3abc7bb5ed52fd861fc03822a35a48510ee1b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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) {
  try {
    return Boolean(renderToString(h(Component, props)));
  } catch (e) {}
  return false;
}

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

export default {
  check,
  renderToStaticMarkup,
};