$derived: Declarative Computed Values
Compute values that automatically update when their dependencies change.
Computed State
Use $derived(expr) to compute a value from reactive sources.
let count = $state(0);
let doubled = $derived(count * 2);Auto Tracked
Svelte tracks dependencies of the expression automatically. The derived updates when any source changes.
All lessons in this course
- Why Runes: Moving Beyond the Compiler Magic
- $state: Fine-Grained Reactivity
- $derived: Declarative Computed Values
- $effect: Side Effects