mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-04-02 20:15:53 +02:00
* 🔤 ⚡ T now uses DocumentFragment * 🔤 * 🔤 ⚡ * 🐛 lint * ⚡ cleanup * ⚡ 🔤 lib download * ⚡ 🔤 ui * ⚡ reorganize files * ⚡ on.host * 🐛 on.* types * ⚡ 🔤 cdn * 🔤 converter * 🐛 signal.set(value, force) * ⚡ 🔤 * 🔤 ⚡ converter - convert also comments * ⚡ bs/build * 🔤 ui p14 * 🔤 * 🔤 Examples * 🔤 * 🐛 now only el(..., string|number) * 🐛 fixes #38 * 🔤 * ⚡ on.host → on.defer * 🔤 * 📺
31 lines
762 B
JavaScript
31 lines
762 B
JavaScript
import { el } from "deka-dom-el";
|
|
import { S } from "deka-dom-el/signals";
|
|
|
|
// A HelloWorld component using the 3PS pattern
|
|
function HelloWorld({ emoji = "🚀" }) {
|
|
// PART 1: Create reactive state
|
|
const clicks = S(0);
|
|
|
|
return el().append(
|
|
// PART 2: Bind state to UI elements
|
|
el("p", {
|
|
className: "greeting",
|
|
// This paragraph automatically updates when clicks changes
|
|
textContent: S(() => `Hello World ${emoji.repeat(clicks.get())}`)
|
|
}),
|
|
|
|
// PART 3: Update state in response to events
|
|
el("button", {
|
|
type: "button",
|
|
textContent: "Add emoji",
|
|
// When clicked, update the state
|
|
onclick: () => clicks.set(clicks.get() + 1)
|
|
})
|
|
);
|
|
}
|
|
|
|
// Use the component in your app
|
|
document.body.append(
|
|
el(HelloWorld, { emoji: "🎉" })
|
|
);
|