Performance: Readonly props
MEDIUM IMPACT
Readonly props affect how data flows and updates between components, impacting rendering speed and user interaction responsiveness.
<script> export let count; // Child treats count as readonly and emits event to parent import { createEventDispatcher } from 'svelte'; const dispatch = createEventDispatcher(); function increment() { dispatch('increment'); } </script> <button on:click={increment}>{count}</button>
<script> export let count; // Child modifies count directly function increment() { count += 1; } </script> <button on:click={increment}>{count}</button>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Child modifies prop directly | Multiple updates | Multiple reflows per update | High paint cost due to frequent changes | [X] Bad |
| Child treats prop as readonly and emits events | Minimal updates | Single reflow per interaction | Low paint cost | [OK] Good |