Search code examples
sveltesvelte-3

How to conditional add and remove `use:` property in Svelte 3?


Is there a way to elegantly and conditionally add and remove use: property in Svelte 3?

Example:

<script>
    import {classes} from "./functions.js"

    export let originalClasses
</script>

<button use:classes>Button</button>

Is there a way to add or remove use:classes if originalClasses is true?


Solution

  • Actions in Svelte can receive a parameter, which you could use to enable or disable the effect.