Svelte · Middle · Question 16 of 75

What is an attachment ({@attach})?

<script>
  function autofocus(node) {
    node.focus();
  }
</script>

<input {@attach autofocus} />

Explanation

Added in Svelte 5.29 as a more flexible replacement for use: actions. Attachments can also be passed through components via spread props.

Further reading

Problem with a question

Svelte · Middle · question 16

Test yourself

Take the Svelte · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz