Performance: Why props pass data to children
Passing data via props affects how efficiently components update and render in the browser.
<ChildComponent {smallProp} />
<script>
export let smallProp;
</script><ChildComponent {largeObject} />
<script>
export let largeObject;
</script>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Passing large objects as props | Many updates to child DOM | Multiple reflows per update | High paint cost due to layout changes | [X] Bad |
| Passing minimal, specific props | Few DOM updates | Single or no reflows | Low paint cost | [OK] Good |
title in a Svelte child component?export let to receive data from parents.export let title;, which makes title a prop.<ChildComponent title="Hello" />and the child component code:
export let title;
<h1>{title} World</h1>
title to the child component.export let title; and uses it inside an <h1> tag with additional text " World".name?let name;
<p>Hello {name}</p>
let name; but does not use export, so it won't receive the prop from the parent.export let to be accessible from the parent component.Button component that changes its label based on a prop called text. Which approach correctly uses props to achieve this in Svelte?export let to receive data from the parent.export let text;
<button>{text}</button> declares export let text; and uses {text} inside the button, making it reusable with different labels.Pass the test and this pattern moves unknown