Helpers / JSX
fromJsx — convert a React tree into Takumi nodes outside the renderer.
takumi-js/helpers/jsx exposes fromJsx, the same function render() calls internally. Import it directly when you want to inspect or cache the resulting node tree, or when you want to assemble nodes from multiple JSX islands before handing them to the renderer.
Functions
fromJsx
import { } from "takumi-js/helpers/jsx";
import { } from "takumi-js";
const { , } = await (
< ="flex items-center justify-center bg-black text-white">
<>Hello</>
</>,
);
await (, { : 800, : 200, });Walks the React element tree and returns { node, stylesheets }. Fragments, memo, and forwardRef are followed directly. Function components are invoked synchronously; if they throw the "invalid hook call" error (i.e. they use hooks or context), fromJsx falls back to react-dom/server's renderToStaticMarkup and re-parses the result as HTML.
The JSX you pass must therefore be serializable. Event handlers and refs are stripped. <style> children are collected into stylesheets rather than rendered as nodes.
Options
Prop
Type
Description
defaultStyles?unionOverride or disable the default Chromium style presets.
If an object is provided, all the default style presets will be overridden.
If false is provided explicitly, no default style presets will be used.
tailwindClassesProperty?stringThe JSX prop name used to pass Tailwind classes.
Result
Prop
Type
Description
nodeNodestylesheetsarrayStyle presets
defaultStylePresets
A Partial<Record<keyof JSX.IntrinsicElements, CSSProperties>> mirroring Chromium's html.css user-agent stylesheet — body has margin: 8, p has block margins, headings have their <hN> font sizes, and so on. Pass defaultStyles: false to fromJsx to opt out entirely, or pass your own object to override.
import { , } from "takumi-js/helpers/jsx";
await (<>no margins please</>, {
: { ..., : { : "block" } },
});Last updated on