Svelte · Junior · Question 10 of 76

How do you declare reactive state in Svelte 5?

<script>
  let count = $state(0);
</script>

<button onclick={() => count++}>{count}</button>

Explanation

count is just a number, there is no .value or setter. Plain let declarations being reactive was Svelte 4 behaviour; in runes mode you need $state.

Further reading

Problem with a question

Svelte · Junior · question 10

Test yourself

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

Take this quiz