hono-jsx

安装量: 85
排名: #9351

安装

npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill hono-jsx

Hono JSX - Server-Side Rendering Overview

Hono provides a built-in JSX renderer for server-side HTML generation. It supports async components, streaming with Suspense, and integrates seamlessly with Hono's response system.

Key Features:

Server-side JSX rendering Async component support Streaming with Suspense Automatic head hoisting Error boundaries Context API Zero client-side hydration overhead When to Use This Skill

Use Hono JSX when:

Building server-rendered HTML pages Creating email templates Generating static HTML Streaming large HTML responses Building MPA (Multi-Page Applications)

Not for: Interactive SPAs (use React/Vue/Svelte instead)

Configuration TypeScript Configuration // tsconfig.json { "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "hono/jsx" } }

Alternative: Pragma Comments / @jsx jsx */ / @jsxImportSource hono/jsx */

Deno Configuration // deno.json { "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "npm:hono/jsx" } }

Basic Usage Simple Rendering import { Hono } from 'hono'

const app = new Hono()

app.get('/', (c) => { return c.html( <html> <head> <title>Hello Hono</title> </head> <body>

Hello, World!

</body> </html> ) })

Components import { Hono } from 'hono' import type { FC } from 'hono/jsx'

// Define props type type GreetingProps = { name: string age?: number }

// Functional component const Greeting: FC = ({ name, age }) => { return (

Hello, {name}!

{age &&

You are {age} years old.

}
) }

const app = new Hono()

app.get('/hello/:name', (c) => { const name = c.req.param('name') return c.html() })

Layout Components import type { FC, PropsWithChildren } from 'hono/jsx'

const Layout: FC<PropsWithChildren<{ title: string }>> = ({ title, children }) => { return ( <html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>{title}</title> <link rel="stylesheet" href="/styles.css" /> </head> <body>

{children}

© 2025 My App

</body> </html> ) }

app.get('/', (c) => { return c.html(

Welcome!

This is my home page.

) })

Async Components Basic Async const AsyncUserList: FC = async () => { const users = await fetchUsers()

return (

    {users.map(user => (
  • {user.name}
  • ))}
) }

app.get('/users', async (c) => { return c.html() })

Nested Async Components const UserProfile: FC<{ id: string }> = async ({ id }) => { const user = await fetchUser(id)

return (

{user.name}

{user.email}

) }

const UserPosts: FC<{ userId: string }> = async ({ userId }) => { const posts = await fetchUserPosts(userId)

return (

Posts

{posts.map(post => (

{post.title}

{post.excerpt}

))}
) }

Streaming with Suspense Basic Streaming import { Suspense, renderToReadableStream } from 'hono/jsx/streaming'

const SlowComponent: FC = async () => { await new Promise(resolve => setTimeout(resolve, 2000)) return

Loaded after 2 seconds!
}

app.get('/stream', (c) => { const stream = renderToReadableStream( <html> <body>

Streaming Demo

Loading...\