What is a Svelte Action? Write a simple logging action.

WHAT IT TESTS: Whether you understand a Svelte action as a lifecycle function attached to a DOM node via use: and can write its minimal signature. ANSWER OUTLINE: Define a function receiving the node, log a message, and optionally return destroy.
WHAT IT TESTS: Whether you understand that a Svelte action is a lifecycle function bound to a specific DOM element through the use: directive, giving you imperative control over that node. ANSWER OUTLINE: First, define a function that accepts the DOM node as its first argument; second, run console.log inside the function body so it executes when the element is mounted; third, mention that you can return an object with an optional destroy method for cleanup.
Read the original → svelte.dev
- #svelte
- #actions
- #dom
- #lifecycle
- #frontend
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.