Skip to content
Discussion options

You must be logged in to vote

According to ¹, props are a way to pass data from parent components to children components in Svelte. To declare props, you use the export keyword in your component script⁵. To pass props to a child component, you use attributes on the component tag⁴. For example:

<script>
  export let name;
</script>

<h1>Hello {name}!</h1>
<script>
  import Greeting from './Greeting.svelte';
</script>

<Greeting name="Alice" />

To pass arbitrary props to a child component, you can use the $$restProps object⁶. This object contains any attributes that are not declared as props by the child component. For example:

<script>
  export let name;
</script>

<h1>Hello {name}!</h1>

<div {...$$restProps}></div>
<s…

Replies: 1 comment

Comment options

jeblister
Mar 12, 2023
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by jeblister
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant