HTML

Introducció

HTML

html Helper

The html Helper lets you write HTML in JavaScript template literal with a tag named html.

You have to escape these strings by yourself.

import { Hono } from 'hono'
import { html} from 'hono/html'

const app = new Hono()

app.get('/student/:username', (c) => {
  const { username } = c.req.param()
  return c.html(
      html`<!doctype html>
      <h1>Hello, ${username}!</h1>`
  )
})

Using raw(), the content will be rendered as is.

TSX

If you want to use TSX, rename the file to src/index.tsx and configure it (check with each runtime as it is different).

or using JSX syntax.

Below is an example using JSX.

const View = () => {
  return (
    <html>
      <body>
        <h1>Hello Hono!</h1>
      </body>
    </html>
  )
}

app.get('/page', (c) => {
  return c.html(<View />)
})