Home United States USA — software How to Pass Arguments to Events Like On:Click in Svelte

How to Pass Arguments to Events Like On:Click in Svelte

121
0
SHARE

It’s common to want to add an argument or parameter to a function called in a Svelte event, but it doesn’t work exactly how you’d think.
Join the DZone community and get the full member experience. Svelte events are the way we add interactivity to components in Svelte. A common issue with Svelte events is adding arguments to functions called within them. For example, suppose we have a basic counter, which increases any time the user clicks on it:
This works fine, but let’s say we want to change it so that we increase the counter by a certain amount whenever it is clicked.

Continue reading...