picojsx
v0.1.0
Published
Tiny (under 1k), zero-dependency JSX renderer - built for Cloudflare Workers, but works everywhere!
Downloads
4
Maintainers
Readme
picojsx
Tiny (under 1k), zero-dependency JSX renderer - built for Cloudflare Workers, but works everywhere!
Installation
npm install picojsx
Examples
Render JSX to HTML
// @jsxRuntime automatic
// @jsxImportSource picojsx
import { renderToString } from "picojsx";
let vnode = <div class="foo">content</div>;
let html = renderToString(vnode);
console.log(html);
// <div class="foo">content</div>
Render JSX inside Workers
// @jsxRuntime automatic
// @jsxImportSource picojsx
import { render } from "picojsx";
export default {
fetch: (request) => render(<h1>Hello {request.url}!</h1>),
};
Run it with wrangler:
wrangler dev --local index.jsx
API
renderToString(vnode): string
Renders the given vnode
to HTML.
render(vnode, options = {}): Response
Renders the given vnode
to HTML and wraps it in a Response
.