Writable Stores in Svelte
From the Svelte cheat sheet · Stores · verified Jul 2026
Writable Stores
Creating and using writable stores
javascript
// stores.js
import { writable } from 'svelte/store';
export const count = writable(0);
export const user = writable({ name: 'Guest' });
// Component.svelte
<script>
import { count } from './stores.js';
</script>
<button onclick={() => $count++}>
Count: {$count}
</button>📦 Global state accessible from any component
$ Auto-subscription with automatic cleanup
🔄 update() for transforming current value
💾 Can persist to localStorage easily