Svelte Syntax
Svelte 5 template syntax and runes.
Runes
$state(0)- Reactive state
$derived(expr)- Computed value
$derived.by(() => ...)- Computed with a function
$effect(() => {})- Side effect
$props()- Component props
$bindable(d)- Two-way bindable prop
Template
{#if cond}β¦{/if}- Conditional
{#each list as item, i}β¦{/each}- Loop
{#await promise}β¦{:then v}β¦{/await}- Await
{#key value}β¦{/key}- Re-create on change
{@render snippet()}- Render a snippet
{#snippet row(x)}β¦{/snippet}- Define a snippet
Bindings & events
bind:value={x}- Two-way bind
onclick={fn}- DOM event
use:action- Use an action
class:active={cond}- Toggle a class