Skip to main content
Props and state are the fundamental ways to manage data in Svelte components. Props pass data from parent to child, while state manages data within a component.

Component Props

Props (short for properties) are how you pass data to components. You pass props just like you pass attributes to elements:

Declaring Props with $props

Inside the child component, receive props with the $props rune:

Type-Safe Props

Add type safety using TypeScript:
Or using JSDoc:

Component State

The $state rune creates reactive state within a component:

Deep Reactive State

Arrays and objects become deeply reactive state proxies:

State in Classes

Use $state in class fields:

Derived State

Create computed values with the $derived rune:
For complex derivations, use $derived.by:

Bindable Props

Create two-way bindings with $bindable:

Updating Props

References to props update automatically when the prop changes. You can temporarily reassign props:
However, avoid mutating props unless they are bindable. Use callback props or $bindable for parent-child communication.

Unique IDs with $props.id()

Generate unique IDs for component instances:

Raw State

For non-reactive objects, use $state.raw:

State Snapshots

Take static snapshots of reactive state: