Complete the code to pass a parameter to the action function.
<script> function highlight(node, [1]) { node.style.backgroundColor = [1].color; return { destroy() { node.style.backgroundColor = ''; } }; } </script> <p use:highlight={{ color: 'yellow' }}>Highlight me!</p>
The second parameter of an action function is the parameters object passed when using the action.
Complete the code to update the action when parameters change.
<script>
function highlight(node, params) {
node.style.backgroundColor = params.color;
return {
[1](newParams) {
node.style.backgroundColor = newParams.color;
}
};
}
</script>The update method is called when the parameters passed to the action change.
Fix the error in the action function parameter usage.
<script>
function tooltip([1]) {
// code to show tooltip
}
</script>The action function must receive the DOM node as the first argument. Parameters are optional as the second argument.
Fill both blanks to correctly destructure parameters in the action function.
<script> function focus(node, [1]) { const { delay, color } = [2]; setTimeout(() => { node.style.outlineColor = color; node.focus(); }, delay); } </script>
The second argument is commonly named params, which you can destructure to get individual parameters.
Fill all three blanks to correctly implement an action with parameters and update method.
<script> function resize(node, [1]) { function applySize() { node.style.width = [2] + 'px'; node.style.height = [3] + 'px'; } applySize(); return { update(newParams) { [1] = newParams; applySize(); } }; } </script>
The action receives params as the second argument. You use params.width and params.height to set sizes. The update method updates params and reapplies the size.