aroma-jsx-engine
Version:
A lightweight and flexible JSX/TSX engine for rendering React components in Node.js applications. Designed to work seamlessly with the [`aroma.js`](https://www.npmjs.com/package/aroma.js) framework, this package allows you to compile and render JSX/TSX co
15 lines (12 loc) • 433 B
JavaScript
const React = require('react');
const ReactDOMServer = require('react-dom/server');
function render(jsxComponent, props = {}) {
try {
const element = jsxComponent({ ...props, React });
const htmlString = ReactDOMServer.renderToString(element);
return htmlString;
} catch (error) {
throw new Error(`JSX rendering failed: ${error.message}`);
}
}
module.exports = { render };