Skip to content

Commit

Permalink
Add clarification on what makes a reactive block reactive to docs. (#…
Browse files Browse the repository at this point in the history
…5729)

* Add clarification on what makes a reactive block reactive to docs.

* Tweak reactive explanation
  • Loading branch information
arackaf authored Dec 6, 2020
1 parent e02c291 commit e5aa04e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions site/content/docs/01-component-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ Any top-level statement (i.e. not inside a block or a function) can be made reac

---

Only values which directly appear within the `$:` block will become dependencies of the reactive statement. For example, in the code below `total` will only update when `x` changes, but not `y`.

```sv
<script>
let x = 0;
let y = 0;
function yPlusAValue(value) {
return value + y;
}
$: total = yPlusAValue(x);
</script>
Total: {total}
<button on:click={() => x++}>
Increment X
</button>
<button on:click={() => y++}>
Increment Y
</button>
```

---

If a statement consists entirely of an assignment to an undeclared variable, Svelte will inject a `let` declaration on your behalf.

```sv
Expand Down

0 comments on commit e5aa04e

Please sign in to comment.