How to JSX to string? #3278
-
|
Hello, I am looking for a way to convert from Hono JSX ( Example use case: I'm using SVG in JSX to generate several variations of a logo (different colors, padding, stroke width). I'd like to be able to write the SVG string to a file. I am aware of the SSG helper functions (https://hono.dev/docs/helpers/ssg), but I'm wondering if there's a more straightforward way. Thank you for Hono! Best HTML templating system I know of! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
@refinedkontrol const svg = <svg><title>SVG</title></svg>
const text = await svg.toString() |
Beta Was this translation helpful? Give feedback.
-
|
My solution (works in node.js runtime): import { renderToString } from 'hono/jsx/dom/server';
import MyComponent from './MyComponent.jsx';
const dom = <MyComponent props={data}></MyComponent>;
const text = renderToString(dom); |
Beta Was this translation helpful? Give feedback.
@refinedkontrol
Try