Repository navigation
tags: [sveltekit, components]
|
Answered by
jeblister
Mar 12, 2023
Replies: 1 comment
|
According to ¹, props are a way to pass data from parent components to children components in Svelte. To declare props, you use the <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 <script>
export let name;
</script>
<h1>Hello {name}!</h1>
<div {...$$restProps}></div><script>
import Greeting from './Greeting.svelte';
</script>
<Greeting name="Bob" class="red" id="greet" />In this case, the Source:
|
0 replies
Answer selected by
jeblister
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
According to ¹, props are a way to pass data from parent components to children components in Svelte. To declare props, you use the
exportkeyword in your component script⁵. To pass props to a child component, you use attributes on the component tag⁴. For example:To pass arbitrary props to a child component, you can use the
$$restPropsobject⁶. This object contains any attributes that are not declared as props by the child component. For example: