Svelte · Middle · Question 48 of 75

What does this code show after clicking the button?

<script>
  let todos = $state([{ text: "A", done: false }]);
  const first = todos[0];
</script>

<button onclick={() => (first.done = true)}>Done</button>
<p>{todos[0].done}</p>

Explanation

Reading an object property from a deep state proxy returns a proxy too. Destructuring primitives, however, loses reactivity.

Further reading

Problem with a question

Svelte · Middle · question 48

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