Svelte & SvelteKit (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What are Component Props in Svelte 5 using `$props()`?
junior LevelCode ExampleComponentsSvelte 5
In Simple Words:
In Svelte 4, props were declared using export let name = 'default'.
In Svelte 5, all props are accessed via the $props() rune using standard JavaScript destructuring:
svelte
<script>
// Props declaration with defaults and TypeScript types
let {
title = 'Default Title',
count = 0,
onincrement
} = $props<{
title?: string;
count?: number;
onincrement?: () => void;
}>();
</script>
<h1>{title} ({count})</h1>
<button onclick={onincrement}>Increment</button>