javascript / beginner
Snippet
Defining Component Props
Props (properties) allow you to pass data from a parent component to a child component. In Svelte, you define a prop by using the 'export' keyword on a variable.
snippet.js
1
2
3
4
5
<script>export let message = 'Hello World';</script><p>Message: {message}</p>
svelte
Breakdown
1
export let message
The 'export' keyword makes this variable a public property that can be set by a parent.
2
= 'Hello World'
Provides a default value in case the parent doesn't pass one.