Svelte · Middle · Question 49 of 75

Why isn't count reactive in the importing component?

// counter.svelte.js
export let count = $state(0);
export function increment() { count += 1; }

Explanation

Svelte reports a compile error for this pattern. export const counter = $state({ count: 0 }) works because you mutate a property.

Further reading

Problem with a question

Svelte · Middle · question 49

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