javascript / beginner
Snippet
Svelte Writable Stores
A writable store is an object that holds a value and allows components to subscribe to changes. It is the primary way to manage shared state in Svelte.
snippet.js
1
2
3
import { writable } from 'svelte/store';export const count = writable(0);
svelte
Breakdown
1
import { writable } from 'svelte/store';
Imports the writable function from Svelte's store module.
2
export const count = writable(0);
Creates a new store with an initial value of 0 and exports it for use in other files.