How do Svelte Stores work and how do you create custom ones?

Tests Svelte store contract mastery. A strong answer defines the subscribe/unsubscribe interface, wraps writable() with custom set/update logic, subscribes via $ prefix or manually, and uses $store in templates.
Tests understanding of Svelte's store contract for cross-component state. A great answer states a store is any object with a subscribe method returning an unsubscribe function. To create a custom writable, import writable from svelte/store, call it with an initial value, then wrap set and update with your logic. In a component, subscribe manually with store.subscribe and cleanup in onDestroy, or use $store for automatic teardown. In templates, read $store directly.
Read the original → svelte.dev
- #svelte
- #state-management
- #stores
- #frontend
- #reactivity
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.