0Pricing
Sveltejs Academy · Lesson

Reactive Variables with let

Declare reactive state in Svelte using plain let declarations.

No Special API

In Svelte, ordinary let declarations in the script block are reactive. There is no useState equivalent.

Declare and Use

Declare a variable and interpolate it in markup. Updating it re-renders the part that depends on it.

<script>
  let count = 0;
</script>

<p>The count is {count}</p>

All lessons in this course

  1. The script template style Structure
  2. Reactive Variables with let
  3. Interpolation: {expression}
  4. Computed Values: $: reactive declarations
← Back to Sveltejs Academy