Skip to content

Commit cd11379

Browse files
authored
clarify when attachments re-run
1 parent 271fd33 commit cd11379

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

documentation/docs/03-template-syntax/[email protected]

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
title: {@attach ...}
33
---
44

5-
Attachments are functions that run when an element is mounted to the DOM. Optionally, they can return a function that is called when the element is later removed from the DOM.
5+
Attachments are functions that run in an [effect]($effect) when an element is mounted to the DOM or when [state]($state) read inside the function updates.
6+
7+
Optionally, they can return a function that is called when the element is later removed from the DOM.
68

79
> [!NOTE]
810
> Attachments are available in Svelte 5.29 and newer.
@@ -55,7 +57,7 @@ A useful pattern is for a function, such as `tooltip` in this example, to _retur
5557
</button>
5658
```
5759

58-
Since the `tooltip(content)` expression runs inside an [effect]($effect), the attachment will be destroyed and recreated whenever `content` changes.
60+
Since the `tooltip(content)` expression runs inside an [effect]($effect), the attachment will be destroyed and recreated whenever `content` changes. The same thing would happen for any state read _inside_ the attachment function when it first runs.
5961

6062
## Inline attachments
6163

0 commit comments

Comments
 (0)