Something went wrong. Try again.
Small functional reactive frontend library
Something went wrong. Try again.
Files
- TypeScript 99%
- HTML <1%
README.md
# Reactive DOM Builder Library — Documentation
> This has been generated via an LLM tbh.
This library provides a lightweight, signal-driven alternative to JSX for building DOM trees, built on top of `@preact/signals-core`. It consists of two modules:
- **`./src/core.ts`** — the `h` proxy for creating elements with reactive props, styles, classes, attributes, and children.
- **`./src/dynamic-content.ts`** — structural control-flow helpers (`Show`, `Repeat`) and a `txt` template-literal helper, for reactivity that plain `h()` children can't express (conditionals, keyed lists).
---
## Part 1: Usage Guide
### 1.1 The `h` proxy — creating elements
`h` is a `Proxy` typed against `HTMLElementTagNameMap`. Any tag name you access on it (`h.div`, `h.span`, `h.input`, `h.button`, …) returns a fully-typed factory function:
```ts
h.div(props?, children?) => HTMLDivElement
```
Basic example:
```ts
const el = h.div(
{ attrs: { id: "greeting" } },
["Hello, world!"]
);
document.body.appendChild(el);
```
Every tag on `HTMLElementTagNameMap` works out of the box — no need to register elements ahead of time. TypeScript will type-check `props` against the *specific* element interface (e.g. `h.input(...)` knows about `.value`, `.checked`, `.type`, etc.; `h.div(...)` does not).
### 1.2 `DynamicValue<T>` — the core reactivity primitive
Almost every prop value can be one of three shapes:
```ts
type DynamicValue<T> = T | Signal<T> | ((el: HTMLElement) => T);
```
| Shape | Behavior |
|---|---|
| Plain value (`T`) | Used as-is, once. |
| `Signal<T>` | Read once for the *initial* render, then **subscribed to** — future signal changes update the DOM automatically. |
| `(el: HTMLElement) => T` | Called once, synchronously, with the element itself. Useful for values that depend on the element (e.g. measuring it) — but **it is not re-run**. It behaves like a plain value, not a live binding, despite the type name. |
⚠️ Only the `Signal` form is reactive. Functions are a one-shot computed-at-creation convenience, not a subscrip…