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:
<script>
let { adjective, count } = $props();
</script>
<p>This component is {adjective}</p>
<p>Count: {count}</p>
<script>
let { class: className, super: trouper = 'lights are gonna find me' } = $props();
</script>
Type-Safe Props
Add type safety using TypeScript: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:
$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:$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: