import 'nuclo'
let seconds = 0
let shown = false
const Timer = () =>
span(
{
onMount: () => {
const id = setInterval(() => { seconds++; update() }, 1000)
return () => clearInterval(id) // runs when the span is removed
},
},
() => `${seconds}s`,
)
export const TimerToggle = () =>
div(
button(() => (shown ? 'Unmount timer' : 'Mount timer'), {
onClick: () => { shown = !shown; update() },
}),
when(() => shown, Timer()),
)