Svelte: Using an action twice throws "same attribute" error

Created on 11 Oct 2020  Â·  5Comments  Â·  Source: sveltejs/svelte

https://svelte.dev/repl/01a14375951749dab9579cb6860eccde?version=3.29.0

<script>
    function action(){}
</script>

<div use:action use:action />
Attributes need to be unique (5:16)
pending clarification

Most helpful comment

You can use it twice like this:

<script>
    function action(){}
    const alias = action;
</script>

<div use:action use:alias />

All 5 comments

Do you want to have the same script run twice on the node?

@peopledrivemecrazy @antony I have a similar question: Is it possible to use an action twice on the same node? I have written a small animation function that looks something like this:

<div use:animate={{trigger: scrollY, opactiy: {start: 0, end: 200, from: 0, to: 1}}} />

It would be very helpful for me if I could use them several times on same element, so i can create in and out scroll animations.

Heya,

It is not. Why not make your action take an array?

On Sun, 18 Oct 2020 at 18:36, Niklas Grewe notifications@github.com wrote:

@peopledrivemecrazy https://github.com/peopledrivemecrazy @antony
https://github.com/antony I have a similar question: Is it possible to
use an action twice on the same node? I have written a small animation
function that looks something like this:

It would be very helpful for me if I could use them several times on same
element.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sveltejs/svelte/issues/5516#issuecomment-711319421,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AABVORP4RNL2O5WJLQUJVYTSLMRQXANCNFSM4SLOAYYQ
.

>


ꜽ . antony jones . http://www.enzy.org

You can use it twice like this:

<script>
    function action(){}
    const alias = action;
</script>

<div use:action use:alias />

You can use it twice like this:

<script>
  function action(){}
  const alias = action;
</script>

<div use:action use:alias />

This works great.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

1u0n picture 1u0n  Â·  3Comments

davidcallanan picture davidcallanan  Â·  3Comments

plumpNation picture plumpNation  Â·  3Comments

mmjmanders picture mmjmanders  Â·  3Comments

sskyy picture sskyy  Â·  3Comments