Svelte · Junior · Question 68 of 76

What does the use: directive (action) receive?

<script>
  function tooltip(node, text) {
    // set up
    return { destroy() { /* clean up */ } };
  }
</script>

<button use:tooltip={"Save changes"}>Save</button>

Explanation

Actions are still supported, but Svelte 5.29+ recommends attachments ({@attach}), which are more flexible and react to state changes.

Further reading

Problem with a question

Svelte · Junior · question 68

Test yourself

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

Take this quiz