Examples · Basics

Counter

A signal in a template: the smallest possible component.

A signal holds state, html`` renders it. ${count} is live because it is the signal itself, not its value: the text node updates in place, nothing else re-renders.

Playground

What to notice

  • ${count} is a subscription; ${count.value} would be a one-time snapshot (the dev build warns about it as E019).
  • mount() gives the setup a scope: every effect and listener created here dies with the component.
  • There is no render function to call again. The template is parsed once, the binding updates the text node.

Change ${count} to ${count.value} and click: the number stops updating.