Recall & Review
beginner
What is a named action in Svelte?
A named action in Svelte is a reusable function that you can apply to HTML elements to add behavior, like event handling or animations, by using the
use: directive with a specific name.Click to reveal answer
beginner
How do you apply a named action to an element in Svelte?
You apply a named action by adding
use:actionName to the HTML element, where actionName is the function you want to run on that element.Click to reveal answer
intermediate
What arguments does a Svelte action function receive?
A Svelte action function receives two arguments: the HTML element it is applied to, and an optional parameter object for configuration.
Click to reveal answer
intermediate
What should a Svelte action return if it needs to clean up?
If cleanup is needed, the action should return an object with a
destroy method that runs when the element is removed or the action is changed.Click to reveal answer
intermediate
Can named actions in Svelte accept parameters? How?
Yes, named actions can accept parameters by passing them like
use:actionName={params}. The action function receives these parameters as the second argument.Click to reveal answer
How do you attach a named action called
highlight to a <div> in Svelte?✗ Incorrect
In Svelte, named actions are attached using the
use: directive followed by the action name.What does a Svelte action function receive as its first argument?
✗ Incorrect
The first argument to a Svelte action function is always the HTML element the action is applied to.
What should a Svelte action return if it needs to clean up when the element is removed?
✗ Incorrect
Returning an object with a
destroy method lets Svelte know how to clean up when the element is removed.How do you pass parameters to a named action in Svelte?
✗ Incorrect
Parameters are passed to named actions using curly braces after the action name, like
use:actionName={params}.Which of these is NOT a valid use of a named action in Svelte?
✗ Incorrect
use:onClick is invalid because event handlers use on:, not use:.Explain how named actions work in Svelte and how you would create and use one.
Think about how you add behavior to elements with functions.
You got /4 concepts.
Describe how to pass parameters to a named action and how the action function handles them.
Consider how you customize the action's effect on the element.
You got /3 concepts.