{#if status === 'success'} <div class="alert success">Operation completed!</div>{:else if status === 'error'} <div class="alert error">Something went wrong</div>{:else if status === 'warning'} <div class="alert warning">Please review</div>{/if}
Avoid too many nested if blocks as they can make templates hard to read. Consider extracting complex logic into separate components or computed values.
Svelte efficiently updates the DOM when conditions change:
Only the affected parts of the DOM are updated
Elements inside false conditions are removed from the DOM
When conditions become true, elements are created fresh
Copy
<script> let show = $state(true); // This will re-run when show changes $effect(() => { console.log('Component mounted:', show); });</script>{#if show} <ExpensiveComponent />{/if}