Actions in Svelte

From the Svelte cheat sheet · Events & Actions · verified Jul 2026

Actions

Reusable element behaviors

javascript
<script>
  function tooltip(node, text) {
    // Setup
    // Return { update, destroy }
  }
</script>

<button use:tooltip={'Hover me'}>
  Button
</button>
🎯 use:action directive for reusable behaviors
🔄 Update function for reactive parameters
🧹 Destroy function for cleanup
📦 Encapsulate complex DOM interactions

More Svelte tasks

Back to the full Svelte cheat sheet