Part 1 / Props / Spread props
If you have an object of properties, you can 'spread' them onto a component instead of specifying each one:
<PackageInfo {...pkg}/>
Conversely, if you need to reference all the props that were passed into a component, including ones that weren't declared with
export
, you can do so by accessing$$props
directly. It's not generally recommended, as it's difficult for Svelte to optimise, but it's useful in rare cases.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<script>
import PackageInfo from './PackageInfo.svelte';
const pkg = {
name: 'svelte',
version: 3,
speed: 'blazingly',
website: 'https://svelte.dev'
};
</script>
<PackageInfo
name={pkg.name}
version={pkg.version}
speed={pkg.speed}
website={pkg.website}
/>
initialising