npm hono 1.4.7
v1.4.7

latest releases: 4.6.2, 4.6.1, 4.6.0...
2 years ago

Summary

This release includes BREAKING CHANGES.

[BREAKING CHANGES] JSX Middleware

  • h is obsolete, removed. Use jsx instead.
  • Don't write app.use('*', jsx()). It's not needed.
  • If you want to return HTML, use c.html()

You can write as below:

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

const app = new Hono()

app.get('/', (c) => {
  return c.html(
    '<!doctype html>' +
    (
      <html>
        <body>
          <p>Hono!</p>
        </body>
      </html>
    )
  )
})

app.fire()

html Middleware

We've added html Middleware. It's powerful to use with JSX middleware. For more information, see documentation

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

const app = new Hono()

interface SiteData {
  title: string
  children?: any
}

const Layout = (props: SiteData) => html`<!DOCTYPE html>
  <html>
    <head>
      <title>${props.title}</title>
    </head>
    <body>
      ${props.children}
    </body>
  </html>`

const Content = (props: { siteData: SiteData; name: string }) => (
  <Layout {...props.siteData}>
    <h1>Hello {props.name}</h1>
  </Layout>
)

app.get('/:name', (c) => {
  const { name } = c.req.param()
  const props = {
    name: name,
    siteData: {
      title: 'JSX with html sample',
    },
  }
  return c.html(<Content {...props} />)
})

app.fire()

Others

  • Implemented Fragment for JSX middleware.

What's Changed

Full Changelog: v1.4.6...v1.4.7

Don't miss a new hono release

NewReleases is sending notifications on new releases.