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.
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.
Optionally, they can return a function that is called when the element is later removed from the DOM.
Optionally, they can return a function that is called before the attachment re-runs, or when the element is later removed from the DOM.
> [!NOTE]
> [!NOTE]
> Attachments are available in Svelte 5.29 and newer.
> Attachments are available in Svelte 5.29 and newer.