Svelte & SvelteKit (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
How does event handling work in Svelte 5 (`onclick` vs. `on:click`)?
junior LevelCode ExampleCLISvelte 5
In Simple Words:
- In Svelte 4: Used custom directive syntax (
on:click={handleClick}). - In Svelte 5: Aligns with modern web standards using standard HTML property attributes:
Component event dispatchers (svelte
<!-- Svelte 5: Standard HTML attribute syntax --> <button onclick={handleClick}>Click Me</button> <input oninput={(e) => text = e.currentTarget.value} />createEventDispatcher) are deprecated in favor of passing callback props (let { onchange } = $props()).