Skip to main content
Hono’s hono/jsx/dom module provides client-side rendering capabilities with a React-compatible API. It allows you to build interactive user interfaces that run in the browser.

Setup

Configure your tsconfig.json for client-side JSX:
tsconfig.json

Basic Rendering

Use the render() function to mount components to the DOM:
Source: src/jsx/dom/render.ts:763-766

Using createRoot (React 18+ API)

For better control over rendering, use the createRoot API:
Source: src/jsx/dom/client.ts:23-66

Hooks

Hono JSX DOM supports all major React hooks:

useState

Manage component state:
Source: src/jsx/hooks/index.ts:182-243

useEffect

Perform side effects:
Source: src/jsx/hooks/index.ts:288-289

useRef

Access DOM elements directly:
Source: src/jsx/hooks/index.ts:319-330

useCallback

Memoize callback functions:
Source: src/jsx/hooks/index.ts:299-316

useMemo

Memoize expensive computations:
Source: src/jsx/hooks/index.ts:348-363

useReducer

Manage complex state logic:
Source: src/jsx/hooks/index.ts:245-258

useContext

Access context values:

useLayoutEffect

Perform DOM measurements before paint:
Source: src/jsx/hooks/index.ts:290-293

useId

Generate unique IDs for accessibility:
Source: src/jsx/hooks/index.ts:366

Event Handling

Handle user interactions with event handlers:
Source: src/jsx/dom/render.ts:115-133

Hydration

Hydrate server-rendered HTML:
Source: src/jsx/dom/client.ts:76-84
In Hono’s implementation, hydrateRoot is equivalent to createRoot().render(). The actual DOM is rendered from scratch.

Refs and DOM Access

Callback Refs

Ref Objects

Source: src/jsx/hooks/index.ts:371-373

forwardRef

Forward refs to child components:
Source: src/jsx/hooks/index.ts:375-382

Suspense and Error Boundaries

Suspense

Handle async operations:

ErrorBoundary

Catch and handle errors:

Transitions

useTransition

Mark updates as transitions:
Source: src/jsx/hooks/index.ts:126-155

useDeferredValue

Defer rendering of non-critical updates:
Source: src/jsx/hooks/index.ts:158-176

Portals

Render children outside the parent hierarchy:
Source: src/jsx/dom/render.ts:782-792

flushSync

Force synchronous updates:
Source: src/jsx/dom/render.ts:768-780

Advanced Hooks

useSyncExternalStore

Subscribe to external stores:
Source: src/jsx/hooks/index.ts:397-425

use (React 19)

Unwrap promises in render:
Source: src/jsx/hooks/index.ts:332-346

Full Example: Todo App

Best Practices

Break down complex components into smaller, reusable pieces.
Define proper types for props, state, and event handlers.
Memoize expensive computations and callbacks to prevent unnecessary re-renders.
Always return cleanup functions from useEffect to prevent memory leaks.
Always provide unique keys when rendering lists to help with reconciliation.

Next Steps

Server Rendering

Learn about server-side JSX rendering

Streaming

Stream HTML with Suspense patterns

JSX Overview

Back to JSX overview