0Pricing
Sveltejs Academy · Lesson

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

  1. Creating a writable Store
  2. Subscribing with $ Auto-subscription
  3. Updating Stores: set() and update()
  4. readable Stores and Custom Start Functions
← Back to Sveltejs Academy