Svelte · Junior · Question 45 of 76

How do you share reactive state between components without stores in Svelte 5?

// counter.svelte.js
export const counter = $state({ value: 0 });

Explanation

Exporting a reassigned primitive (export let count = $state(0)) doesn't work, because importers get a value, not a live binding; mutate an object or export getter functions.

Further reading

Problem with a question

Svelte · Junior · question 45

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