Counter App
Let's build a more comprehensive counter application that demonstrates multiple Element features.
import { createSignal, html } from "@dmnchzl/element";
function Counter() {
const [count, setCount] = createSignal(0);
const increment = () => setCount(count() + 1);
const decrement = () => setCount(count() - 1);
const reset = () => setCount(0);
return html`
<div class="container">
<h2>Count: ${count}</h2>
<div class="btn-grp">
<button onclick="${decrement}">-</button>
<button onclick="${reset}">Reset</button>
<button onclick="${increment}">+</button>
</div>
</div>
`;
}
const root = document.getElementById("root") as HTMLElement;
root.appendChild(Counter());Advanced Usage
This example shows how to use createComputed to derive values from signals:
Last updated