Kamod Hooks – 从 ahooks 移植的 Preact hooks 库
Kamod Hooks – a Preact hooks library ported from ahooks

原始链接: https://kamod-ch.github.io/kamod-hooks/

**kamod-hooks** 是一个轻量级的 Preact 优先库,提供了一系列类型化且支持摇树优化(tree-shakeable)的钩子(hooks),旨在提升开发效率。与那些封装 React API 的库不同,kamod-hooks 是专为 Preact 构建的,确保了原生兼容性,并且其核心库没有任何运行时依赖。 该库强调开发者友好体验,提供了 78 个已记录的钩子,并配有 81 个交互式实时演示。这种“所见即所得”的模式允许开发者在浏览器中直接测试行为、查看精确的 TypeScript 签名并验证边缘情况。 主要特性包括: * **Preact 优化:** 专为 Preact 生态系统编写。 * **支持摇树优化:** 支持主包导入和按需钩子子路径导入,以最大限度减小包体积。 * **实用性强:** 涵盖了存储、观察者、全屏和 URL 状态等必要的浏览器原生功能。 * **即插即用:** 文档本身即是模板,提供可直接用于生产环境的代码模式,方便复制使用。 无论您是需要复杂的状态管理还是简单的浏览器原生钩子,kamod-hooks 都提供了一个透明、类型安全且高度模块化的工具包,以加速您的 Preact 开发工作流。

抱歉。
相关文章

原文

A lightweight collection of typed, tree-shakeable hooks built specifically for Preact.

kamod-hooksPreact-first · Typed · Tree-shakeable

Retro docs, modern hooks

Start with setup, verify behavior in live demos, and copy implementation-ready hook patterns with published TypeScript signatures.

78documented hooks

81live demos

0runtime deps in core

Install

pnpm add @kamod-ch/hooks preact

live-demo.tsx

Preview the docs experience

Test a real hook, inspect the exact source, and confirm the API shape before you implement it.

LiveReal interactive state

ExactCopy the shown source

TypedMatch the published package

Layout: list

import { useToggle } from '@kamod-ch/hooks'

export default function UseToggleDemo() {
  const [value, actions] = useToggle('list', 'grid')

  return (
    <div>
      <p><strong>Layout:</strong> {value}</p>
      <div class="demo-actions">
        <button type="button" onClick={actions.toggle}>Toggle</button>
        <button type="button" onClick={actions.setLeft}>Set list</button>
        <button type="button" onClick={actions.setRight}>Set grid</button>
      </div>
    </div>
  )
}
Why kamod-hooks

Focused on practical Preact usage

The library mirrors the real implementation in packages/core and keeps the docs grounded in shippable examples.

PX

Preact-first

Hooks are authored for Preact instead of wrapping a React-focused API surface.

TS

Typed by default

Distributed declarations stay aligned with implementation and generated docs output.

API

Tree-shakeable exports

Import from the main package or use per-hook subpaths without extra runtime cost.

WEB

Browser-native hooks

Storage, observers, fullscreen, WebSocket, and URL state are covered with concrete examples.

How it works

Go from overview to code quickly

Use the docs like a template: start with the guide, verify behavior in a demo, then copy the exact source shape you need.

  1. 01

    Read the guide

    Install the package, choose an import style, and review SSR notes before implementation.

  2. 02

    Test a live example

    Use an interactive demo to validate behavior, defaults, and edge cases before shipping.

  3. 03

    Copy the exact API

    Use the page signature and demo source as the baseline for production usage.

Explore

Move from overview to implementation details

Start with the guide, scan the full hooks index, or jump directly to the exported utilities.

Start with the docs, then ship faster.

Use the getting-started guide for setup, then jump into the hook pages for demos, signatures, and implementation-ready examples.

联系我们 contact @ memedata.com