Skip to content

Commit f8e6696

Browse files
committed
update docs
1 parent be46c94 commit f8e6696

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: {@attach ...}
44

55
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.
66

7+
> [!NOTE]
8+
> Attachments are available in Svelte 5.29 and newer.
9+
710
```svelte
811
<script>
912
function myAttachment(node) {
@@ -18,6 +21,8 @@ Attachments are functions that run when an element is mounted to the DOM. Option
1821
<div {@attach myAttachment}>...</div>
1922
```
2023

24+
An element can have any number of attachments.
25+
2126
## Attachment factories
2227

2328
A useful pattern is for a function, such as `tooltip` in this example, to _return_ an attachment ([demo](/playground/untitled#H4sIAAAAAAAAE3VT0XLaMBD8lavbDiaNCUlbHhTItG_5h5AH2T5ArdBppDOEMv73SkbGJGnH47F9t3un3TsfMyO3mInsh2SW1Sa7zlZKo8_E0zHjg42pGAjxBPxp7cTvUHOMldLjv-IVGUbDoUw295VTlh-WZslqa8kxsLL2ACtHWxh175NffnQfAAGikSGxYQGfPEvGfPSIWtOH0TiBVo2pWJEBJtKhQp4YYzjG9JIdcuMM5IZqHMPioY8vOSA997zQoevf4a7heO7cdp34olRiTGr07OhwH1IdoO2A7dLMbwahZq6MbRhKZWqxk7rBxTGVbuHmhCgb5qDgmIx_J6XtHHukHTrYYqx_YpzYng8aO4RYayql7hU-1ZJl0akqHBE_D9KLolwL-Dibzc7iSln9XjtqTF1UpMkJ2EmXR-BgQErsN4pxIJKr0RVO1qrxAqaTO4fbc9bKulZm3cfDY3aZDgvFGErWjmzhN7KmfX5rXyDeX8Pt1mU-hXjdBOrtuB97vK4GPUtmJ41XcRMEGDLD8do0nJ73zhUhSlyRw0t3vPqD8cjfLs-axiFgNBrkUd9Ulp50c-GLxlXAVlJX-ffpZyiSn7H0eLCUySZQcQdXlxj4El0Yv_FZvIKElqqGTruVLhzu7VRKCh22_5toOyxsWqLwwzK-cCbYNdg-hy-p9D7sbiZWUnts_wLUOF3CJgQAAA==)):

documentation/docs/03-template-syntax/13-use.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
title: use:
33
---
44

5+
> [!NOTE]
6+
> In Svelte 5.29 and newer, consider using [attachments](attach) instead, as they are more flexible and composable.
7+
58
Actions are functions that are called when an element is mounted. They are added with the `use:` directive, and will typically use an `$effect` so that they can reset any state when the element is unmounted:
69

710
```svelte

packages/svelte/src/attachments/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ATTACHMENT_KEY } from '../constants.js';
2020
*
2121
* <button {...props}>click me</button>
2222
* ```
23+
* @since 5.29
2324
*/
2425
export function createAttachmentKey() {
2526
return Symbol(ATTACHMENT_KEY);

0 commit comments

Comments
 (0)