跳转到正文

htmx ​

结合 htmx 使用 Hono。

typed-htmx ​

使用 typed-htmx,可以在编写 JSX 时使用 htmx 属性的 TypeScript 类型定义。 我们可以遵循 typed-htmx 示例项目中的模式,将它与 hono/jsx 结合使用。

安装包:

sh
npm i -D typed-htmx

在 src/global.d.ts(使用 HonoX 时为 app/global.d.ts)中导入 typed-htmx 类型:

ts
import 'typed-htmx'

使用 typed-htmx 的类型定义扩展 Hono 的 JSX 类型:

ts
// A demo of how to augment foreign types with htmx attributes.
// In this case, Hono sources its types from its own namespace, so we do the same
// and directly extend its namespace.
declare module 'hono/jsx' {
  namespace JSX {
    interface HTMLAttributes extends HtmxAttributes {}
  }
}

另请参阅 ​

基于 MIT 许可证发布。