Svelte · Middle · Question 16 of 75
What is an attachment ({@attach})?
<script>
function autofocus(node) {
node.focus();
}
</script>
<input {@attach autofocus} />- ✓Correct answer: A function that runs when an element is mounted, inside an effect; it can return a cleanup and re-runs when its state changes
- 2A file upload helper
- 3A way to attach CSS to a component
Explanation
Added in Svelte 5.29 as a more flexible replacement for use: actions. Attachments can also be passed through components via spread props.