0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/renderers/react/server.js
2021-05-26 18:31:27 +00:00

20 lines
525 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) {
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,
};