Skip to content

Quick start

Mini Reactive components are functions that create DOM nodes. Read a signal inside a binding and the runtime updates that binding when the value changes.

Counter

Loading the example…

View source
counter.ts
import { mount, signal } from "min-reactive-framework";
import type { Dispose } from "min-reactive-framework";
import { button, div, output, span } from "min-reactive-framework/html";
import type { DemoLanguage } from "../example-language.js";
export function run(target: HTMLElement, lang: DemoLanguage): Dispose {
const count = signal(0);
return mount(target, () =>
div(
{ class: "mr-demo-line" },
button(
{
type: "button",
on: {
click: () => {
count.value++;
},
},
},
lang === "ru" ? "Увеличить" : "Increment",
),
span(lang === "ru" ? "Счётчик" : "Count"),
output({ "aria-live": "polite" }, count),
),
);
}

The archive contains the ready-made library in dist/ and two pages in examples/plain/. Open classic.html directly from disk, or serve the extracted directory over HTTP and open examples/plain/ for the ESM example.

If you already have a project checkout, pnpm install --frozen-lockfile followed by pnpm build produces the same library files locally.

Place the complete dist/ directory beside index.html. The ESM entry points use shared chunks, so keep their relative paths.

<!doctype html>
<html lang="en">
<meta charset="utf-8" />
<title>Mini Reactive counter</title>
<main id="app"></main>
<script type="module" src="./app.js"></script>
</html>
app.js
import { mount, signal } from "./dist/index.js";
import { button, p, section } from "./dist/html.js";
mount(document.getElementById("app"), () => {
const count = signal(0);
return section(
p("Count ", count),
button(
{
on: {
click: () => {
count.value++;
},
},
},
"Increment",
),
);
});

Serve the folder over HTTP, for example with python3 -m http.server 8000 from that directory.

With p(count), the text follows the signal. With p(() => count.value * 2), the runtime tracks the signals read by the expression. Passing p(count.value) captures the value during setup. Keep the disposer returned by mount if the application will be removed or replaced.

Continue with signals and effects or components and children.