Svelte Component Props

Props allow you to pass data from a parent component to a child component. This page demonstrates different ways to work with props in Svelte.

Basic Props Example

Hello Svelte!

This is a simple card component with props

Description length: 42 characters

Example usage:

<Card 
  title="Hello Svelte!" 
  description="This is a simple card component with props" 
  type="info" 
/>

Passing Multiple Props

Basic Props

Simple passing of string, number and boolean props

Description length: 50 characters

Spread Props

Using the spread operator to pass multiple props at once

Description length: 56 characters

Default Props

Components can define default values for props

Description length: 46 characters

Using #each with props:

{#each cards as card}
  <Card 
    title={card.title}
    description={card.description}
    type={card.type} 
  />
{/each}

Spread Props

Spread Props

Using the spread operator to pass multiple props at once

Description length: 56 characters

Using the spread operator:

<Card {...card} />

This passes all properties of the object as individual props.

Default Props

Default Props Example

No description provided

Description length: 23 characters

Component with default props:

<script>
  export let title;
  export let description = "Default description";
  export let type = "default";
</script>

Reactive Props

Count: 0

Reactive Props

This prop updates when parent state changes. Count: 0

Description length: 53 characters