---
name: hono-jsx
description: Hono JSX - server-side rendering, streaming, async components, and HTML generation patterns
user-invocable: false
disable-model-invocation: true
skill_version: 1.0.0
updated_at: 2025-01-03T00:00:00Z
tags: [hono, jsx, ssr, streaming, html, components, suspense]
progressive_disclosure:
entry_point:
summary: "Server-side JSX rendering with streaming, Suspense, and async components"
when_to_use: "Rendering HTML on server, building SSR apps, streaming responses, or creating HTML templates"
quick_start: "1. Configure tsconfig jsxImportSource 2. Create .tsx components 3. Render with c.html()"
references: []
context_limit: 800
---
# 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
```json
// tsconfig.json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx"
}
}
```
### Alternative: Pragma Comments
```tsx
/** @jsx jsx */
/** @jsxImportSource hono/jsx */
```
### Deno Configuration
```json
// deno.json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "npm:hono/jsx"
}
}
```
## Basic Usage
### Simple Rendering
```tsx
import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) => {
return c.html(
Hello Hono
Hello, World!
)
})
```
### Components
```tsx
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
```tsx
import type { FC, PropsWithChildren } from 'hono/jsx'
const Layout: FC> = ({ title, children }) => {
return (
{title}
{children}
)
}
app.get('/', (c) => {
return c.html(
Welcome!
This is my home page.
)
})
```
## Async Components
### Basic Async
```tsx
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
```tsx
const UserProfile: FC<{ id: string }> = async ({ id }) => {
const user = await fetchUser(id)
return (
)
}
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
```tsx
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(
Streaming Demo
Loading...}>
)
return c.body(stream, {
headers: {
'Content-Type': 'text/html; charset=UTF-8',
'Transfer-Encoding': 'chunked'
}
})
})
```
### Multiple Suspense Boundaries
```tsx
const Page: FC = () => {
return (
Dashboard
Loading user...}>
Loading stats...}>
Loading feed...}>
)
}
```
## Error Boundaries
```tsx
import { ErrorBoundary } from 'hono/jsx'
const RiskyComponent: FC = () => {
if (Math.random() > 0.5) {
throw new Error('Random error!')
}
return Success!
}
const ErrorFallback: FC<{ error: Error }> = ({ error }) => {
return (
Something went wrong
{error.message}
)
}
app.get('/risky', (c) => {
return c.html(
)
})
```
### Async Error Boundaries
```tsx
const AsyncRiskyComponent: FC = async () => {
const data = await fetchData()
if (!data) {
throw new Error('Data not found')
}
return {data}
}
// Error boundary catches async errors too
Error: {error.message}
}>
```
## Context API
### Creating Context
```tsx
import { createContext, useContext } from 'hono/jsx'
type Theme = 'light' | 'dark'
const ThemeContext = createContext('light')
const ThemedButton: FC<{ label: string }> = ({ label }) => {
const theme = useContext(ThemeContext)
const className = theme === 'dark' ? 'btn-dark' : 'btn-light'
return
}
const App: FC<{ theme: Theme }> = ({ theme, children }) => {
return (
{children}
)
}
app.get('/', (c) => {
const theme = c.req.query('theme') as Theme || 'light'
return c.html(
)
})
```
## Head Hoisting
Tags like ``, ``, ``, and `')}