onMount executes a callback after the component is mounted in the browser. It doesn't run during server-side rendering.
Return a function to clean up when the component is removed. Here, we'll stop our timer.
<script>
import { onMount } from 'svelte';
let seconds = $state(0);
onMount(() => {
const timer = setInterval(() => seconds++, 1000);
return () => clearInterval(timer);
});
</script>
<p>You've been working on your todos for {seconds} seconds.</p>