Question
Why does the following event handler work in a Svelte component?
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.