$derived rune:
$derived(...) should be free of side-effects. Svelte will disallow state changes (e.g. count++) inside derived expressions.
Signature
The expression to derive from. Should be free of side-effects.
$state, you can mark class fields as $derived.
Code in Svelte components is only executed once at creation. Without the
$derived rune, doubled would maintain its original value even when count changes.$derived.by
$derived.by which accepts a function as its argument:
A function that returns the derived value. Should be free of side-effects.
$derived(expression) is equivalent to $derived.by(() => expression).
Understanding dependencies
Anything read synchronously inside the$derived expression (or $derived.by function body) is considered a dependency of the derived state. When the state changes, the derived will be marked as dirty and recalculated when it is next read.
To exempt a piece of state from being treated as a dependency, use untrack.
Overriding derived values
Derived expressions are recalculated when their dependencies change, but you can temporarily override their values by reassigning them (unless they are declared withconst). This can be useful for things like optimistic UI:
Prior to Svelte 5.25, deriveds were read-only.
Deriveds and reactivity
Unlike$state, which converts objects and arrays to deeply reactive proxies, $derived values are left as-is. For example:
bind: to) properties of selected and it will affect the underlying items array. If items was not deeply reactive, mutating selected would have no effect.
Destructuring
If you use destructuring with a$derived declaration, the resulting variables will all be reactive:
Update propagation
Svelte uses something called push-pull reactivity — when state is updated, everything that depends on the state (whether directly or indirectly) is immediately notified of the change (the ‘push’), but derived values are not re-evaluated until they are actually read (the ‘pull’). If the new value of a derived is referentially identical to its previous value, downstream updates will be skipped:large changes, not when count changes, even though large depends on count.