Svelte 5 and runes: explicit reactivity
An overview of $state, $derived, $effect and $props, and how they change the way you write Svelte components.
With Svelte 5 reactivity becomes explicit thanks to runes: special functions recognised by the compiler.
$state
<script>
let count = $state(0);
</script>
<button onclick={() => count++}>Clicked {count} times</button>$derived
Derived values are recalculated automatically when their dependencies change:
let doubled = $derived(count * 2);$props
Props are declared with destructuring, default values included:
let { title, size = 48 } = $props();Event handlers
on:click directives become plain attributes such as onclick. The same goes for onerror on images, used on this blog for the avatar fallback.