Overview
timerTemplate(callback, ms) is a self-ticking template directive: it calls callback immediately, then on every interval, and patches only that child part — without re-rendering the whole component.
The interval clears when the host disconnects and restarts on reconnect. If ms changes between renders, the interval is restarted with the new duration.
timerTemplate vs onInterval
|
API
|
Scope
|
Notes
|
|---|---|---|
timerTemplate(cb, ms)
| Template fragment | Updates only the directed part. No atom required for the clock display itself. |
onInterval(cb, ms)
| Component hook | Side effects in the outer function — set atoms, fetch, etc. See /docs/hooks/timers. |
Live clock with timerTemplate
timerTemplate(callback, ms) calls callback on every tick and patches only the changed portion of the DOM. No atom, no effect — the interval is tied to the directive's lifetime in the template.
Simple countdown display
Return a number/string from the callback — lit-html renders it directly.