Reactive counter
State held in a closure inside afterMount. Listeners
query the shadow root, not the document.
Each example below is a real custom element rendered on this page. The code shown is the same code that's running. Inspect any of them in DevTools to see the Shadow DOM tree.
State held in a closure inside afterMount. Listeners
query the shadow root, not the document.
Children defined declaratively. Each click handler is registered and torn down for you.
theme exposes CSS custom properties on
:host. Children reference them via
var(--name).
Declare observedAttributes and the component
re‑renders whenever a listed attribute changes — even
from outside the component.
emitEvent() dispatches a bubbling, composed
CustomEvent. The page listens at the document level.