Loading SvelteCosmos...
“$effect() executes side effects after the DOM has updated. It automatically registers dependencies on any signals read during its execution and re-runs whenever those signals change.”
Synchronize reactive state with external systems, APIs, canvas renderers, and the browser DOM.
<script>
let count = $state(0);
$effect(() => {
document.title = `Count: ${count}`;
const timer = setInterval(() => console.log('Tick', count), 1000);
return () => clearInterval(timer); // Cleanup
});
</script>Modify the state variable below to watch the signal update the output without VDOM diffing:
Effects are batched in microtasks so multiple synchronous state mutations result in only one effect invocation.