--- title: use: --- - template syntax - how to write - typings - adjust so that `$effect` is used instead of update/destroy? ```svelte use:action ``` ```svelte use:action={parameters} ``` ```ts /// copy: false // @noErrors action = (node: HTMLElement, parameters: any) => { update?: (parameters: any) => void, destroy?: () => void } ``` Actions are functions that are called when an element is created. They can return an object with a `destroy` method that is called after the element is unmounted: ```svelte
``` An action can have a parameter. If the returned value has an `update` method, it will be called immediately after Svelte has applied updates to the markup whenever that parameter changes. > [!NOTE] Don't worry that we're redeclaring the `foo` function for every component instance — Svelte will hoist any functions that don't depend on local state out of the component definition. ```svelte ``` ## Attributes Sometimes actions emit custom events and apply custom attributes to the element they are applied to. To support this, actions typed with `Action` or `ActionReturn` type can have a last parameter, `Attributes`: ```svelte ```