Subscribing with $ Auto-subscription
Use the $ prefix to auto-subscribe and auto-unsubscribe from stores in components.
The $ Prefix
Prefix a store with $ inside a component to auto-subscribe and read its value.
<script>
import { count } from "./stores";
</script>
<p>{$count}</p>Auto-Unsubscribe
Svelte unsubscribes automatically when the component is destroyed. No memory leaks.
All lessons in this course
- Creating a writable Store
- Subscribing with $ Auto-subscription
- Updating Stores: set() and update()
- readable Stores and Custom Start Functions