Svelte · Senior · Question 67 of 75

Why can't a $derived expression change state?

let count = $state(0);
let doubled = $derived(count++ * 2); // ?

Explanation

Side effects belong in event handlers, or, as a last resort, in effects.

Further reading

Problem with a question

Svelte · Senior · question 67

Test yourself

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

Take this quiz