--- name: hono-jsx description: Use when building UI for a Hono app with hono/jsx — pages, layouts, forms, and interactive parts — server-rendered with jsxRenderer, developed and built with Vite, with client components via hono/jsx/dom. TRIGGER when tsconfig has jsxImportSource "hono/jsx", code imports 'hono/jsx', 'hono/jsx/dom', 'hono/jsx-renderer' or 'vite-ssr-components', or the user asks for a page, screen, layout, or form in a Hono project. Never reach for React. --- # Hono JSX Skill Build UI with `hono/jsx`: server-rendered HTML first, a small amount of client-side JSX only where the browser needs state. The `hono` skill covers the JSX syntax and `c.html()`; this skill covers how to structure the app. Cloudflare Workers with Vite is the default setup; see "Other runtimes" for the rest. ## No React `hono/jsx` is the JSX runtime. Do not bring React in: - Do not install `react`, `react-dom`, `@types/react`, or `@vitejs/plugin-react`. Do not import from `react`. - `tsconfig.json` has `"jsx": "react-jsx"` and `"jsxImportSource": "hono/jsx"`. The `react-jsx` value is the transform name, not a React dependency. - Server components are plain functions rendered once per request. No hooks, no state, no event handlers on the server. Need data: make the component `async` and `await`. Need interactivity: a client component with `hono/jsx/dom`, for that part only. - Write `class`, not `className`. - `vite-ssr-components` exports both flavors: import from `vite-ssr-components/hono`, never from `/react`. ## Project Layout (Cloudflare Workers + Vite) Start from what `create-hono` generates with the `cloudflare-workers` template (`npm create hono@next`, or `npx hono init --template cloudflare-workers` in an existing directory): `src/index.ts` with a text response, `cloudflare.config.ts` for the `cf` CLI, and a `vite.config.ts` with only `cloudflare()`. It has no JSX setup; add the pieces below, and match this layout in existing projects instead of inventing a different structure. Verify routes with the Hono CLI from the `hono` skill (`npx hono request /`); it is a dev dependency of the template and runs the app through Vite, so `c.env` has the local bindings automatically. ``` src/ index.tsx # Hono app, routes (renamed from index.ts) renderer.tsx # jsxRenderer layout: ,
, Vite assets client.ts # optional: browser-side code style.css public/ # static files served as-is cloudflare.config.ts # cf CLI: worker name, entrypoint, bindings vite.config.ts ``` ```jsonc // package.json (scripts, from the template) { "dev": "cf dev", "build": "cf build", "deploy": "cf deploy", "typecheck": "cf workers types && tsc" } ``` On top of the template: 1. Rename `src/index.ts` to `src/index.tsx` and point the entrypoint import in `cloudflare.config.ts` at it: ```ts import * as entrypoint from './src/index.tsx' with { type: 'cf-worker' } ``` 2. Install `vite-ssr-components` as a dev dependency and add its plugin: ```ts // vite.config.ts import { cloudflare } from '@cloudflare/vite-plugin' import { defineConfig } from 'vite' import ssrPlugin from 'vite-ssr-components/plugin' export default defineConfig({ plugins: [cloudflare(), ssrPlugin()], }) ``` 3. Add `src/renderer.tsx`, `src/style.css`, and `public/`: ```tsx // src/renderer.tsx import { jsxRenderer } from 'hono/jsx-renderer' import { Link, Script, ViteClient } from 'vite-ssr-components/hono' export const renderer = jsxRenderer(({ children }) => { return (