Svelte · Middle · Question 4 of 75
Why is this an anti-pattern?
let first = $state("Ann");
let last = $state("Lee");
let full = $state("");
$effect(() => {
full = first + " " + last;
});- ✓Correct answer: Syncing state in an effect adds an extra update and possible loops; use
let full = $derived(first + " " + last) - 2Effects can't read two variables
- 3It's fine and recommended
Explanation
Effects are an escape hatch for side effects. If a value can be computed from state, it should be derived.