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;
});

Explanation

Effects are an escape hatch for side effects. If a value can be computed from state, it should be derived.

Further reading

Problem with a question

Svelte · Middle · question 4

Test yourself

Take the Svelte · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz