hono/jsx) converts JSX components directly to HTML strings. This approach is optimized for server performance and integrates seamlessly with Hono’s request/response model.
Setup
Configure yourtsconfig.json for server-side JSX:
tsconfig.json
Using c.html() with JSX
Thec.html() method accepts JSX and returns an HTML response:
Functional Components
Create reusable components as functions:Props and Type Safety
Hono JSX is fully type-safe with TypeScript:Default Props
Components can have default props:Context API
Share data across components without prop drilling:Memo for Performance
Memoize components to avoid re-rendering:Cloning Elements
Clone and modify existing JSX elements:Children Utilities
Manipulate children with the Children API:Handling Events (Server-Side)
On the server, event handlers are rendered as string attributes:For interactive client-side handlers, use
hono/jsx/dom for client-side rendering.SVG Support
Render SVG elements with proper namespace handling:Async Components
Components can be async for data fetching:For streaming async components, see the Streaming documentation.
Raw HTML
Insert raw HTML strings:Boolean Attributes
Hono automatically handles boolean attributes:Error Boundaries
Handle errors gracefully:Layout Composition
Build complex layouts with component composition:Best Practices
Use TypeScript for type safety
Use TypeScript for type safety
Define proper types for all component props to catch errors at compile time.
Keep components pure
Keep components pure
Components should be pure functions that return consistent output for the same input.
Extract reusable components
Extract reusable components
Break down complex UIs into smaller, reusable components.
Use context sparingly
Use context sparingly
Context is great for global data, but overusing it can make components less reusable.
Next Steps
DOM Rendering
Learn about client-side rendering with hono/jsx/dom
Streaming
Stream HTML responses with Suspense
HTML Helper
Use the html helper for template rendering
Middleware
Use the JSX renderer middleware