$derived.by for Complex Derivations
Compute derived values with arbitrary logic using the callback form of $derived.
Multi-Statement Derivations
For derived values needing more than one expression, use the callback form.
let result = $derived.by(() => {
if (count > 10) return "high";
if (count > 5) return "medium";
return "low";
});Same Reactivity
The callback tracks dependencies the same way as a single-expression $derived.
All lessons in this course
- $state.raw for Non-Reactive State
- $derived.by for Complex Derivations
- $effect.root for Manual Cleanup
- Migrating from Svelte 4 to 5