Svelte and SvelteKit 5 · Runes (reactivity)
Share state between components
Put reactive state in a .svelte.ts file and export it. Export an object, because reassigned primitives can't be exported.
// counter.svelte.ts
export const counter = $state({ value: 0 });
export function increment() {
counter.value++;
}
Official Svelte and SvelteKit 5 documentation
More runes (reactivity) commands
- Component skeleton
- Reactive state
- Derived values
- Side effects
- Receive props
- Allow two-way binding of a prop
All runes (reactivity) commands · Svelte and SvelteKit 5 cheatsheet