Appearance
htmx
在使用 htmx 时使用 Hono。
🌐 Using Hono with htmx.
typed-htmx
通过使用 typed-htmx,你可以为 htmx 属性编写带有 TypeScript 定义的 JSX。我可以遵循 typed-htmx 示例项目 中的相同模式,将其用于 hono/jsx。
🌐 By using typed-htmx, you can write JSX with TypeScript definitions for htmx attributes. We can follow the same pattern found on the typed-htmx Example Project to use it with hono/jsx.
安装软件包:
🌐 Install the package:
sh
npm i -D typed-htmx在 src/global.d.ts(如果你使用 HonoX,则为 app/global.d.ts)上,导入 typed-htmx 类型:
🌐 On src/global.d.ts (or app/global.d.ts if you're using HonoX), import the typed-htmx types:
ts
import 'typed-htmx'使用 typed-htmx 定义扩展 Hono 的 JSX 类型:
🌐 Extend Hono's JSX types with the typed-htmx definitions:
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 {}
}
}另请参阅
🌐 See also