Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Why does the following event handler work in a Svelte component?

$
0
0

I have the following component Form.svelte:

<script>   export let onDelete;</script><form><button type="submit">Update</button><button on:click={onDelete()}>Delete</button></form>

and this is the page which is using the component:

<script>  import Form from './Form.svelte';  function onDelete() {    console.log('deleted');  }</script><Form {onDelete} />

According to the Svelte docs and tutorials, we should define the event handler as

<button on:click={() => onDelete()}>Delete</button>

or

<button on:click={onDelete}>Delete</button>

So why does the above code in the Form.svelte component works?

Here is a REPL.


Viewing all articles
Browse latest Browse all 1541

Trending Articles