0
0
Svelteframework~5 mins

Named actions in Svelte - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A<div use:highlight></div>
B<div action:highlight></div>
C<div on:highlight></div>
D<div highlight></div>
What does a Svelte action function receive as its first argument?
AAn event object
BThe HTML element it is applied to
CThe component instance
DThe action's name
What should a Svelte action return if it needs to clean up when the element is removed?
AA promise
BA boolean true
CNothing, cleanup is automatic
DAn object with a destroy() method
How do you pass parameters to a named action in Svelte?
Ause:actionName={params}
Buse:actionName(params)
CactionName={params}
Don:actionName={params}
Which of these is NOT a valid use of a named action in Svelte?
Ause:fade
Buse:tooltip={text}
Cuse:onClick
Duse:draggable
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.