astro/packages/renderers/renderer-react/server.js
2021-05-28 22:20:42 +00:00

21 lines
613 B
JavaScript

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,
};