Free knowledge blog: linux, programming, open source, databases, android, frameworks, web and computing in general
In Svelte we can define functions that are going to be called when an event is triggered. For example, to call holaMundo
on the click
of an element we can indicate it as on:click={holaMundo}
Sometimes it is necessary to pass parameters to that function inside a Svelte component, but we cannot indicate it like this:
on:click={holaMundo(parameter)}
Since that will execute the function as soon as the component is loaded, and won’t wait for the click.
In this post I will show you how to pass arguments to functions in Svelte without calling them automatically.