Interactive Lab

Svelte 5 Runes & SvelteKit 2 Reactive Engine

Master fine-grained reactivity with $state and $derived, component parameter snippets replacing slots, and two-way $bindable properties.

Svelte5Engine.svelte
<!-- Svelte 5 Component Architecture -->
<script lang="ts">
  import type { Snippet } from 'svelte';

  // 1. $props & $bindable two-way bindings
  let { 
    count = $bindable(0), 
    header, 
    children 
  }: { 
    count?: number; 
    header?: Snippet<[string]>; 
    children?: Snippet; 
  } = $props();

  // 2. Fine-grained universal reactive runes
  let multiplier = $state(2);
  let total = $derived(count * multiplier);
  
  // 3. Side-effect runes
  $effect(() => {
    console.log(`Synchronized total: ${total}`);
  });
</script>

<!-- 4. Snippet Invocation (Replacing Legacy Slots) -->
<div class="card">
  {#if header}
    {@render header('Active State')}
  {/if}
  <button onclick={() => count++}>Count: {count} (x{multiplier} = {total})</button>
  {@render children?.()}
</div>

Svelte 5 Reactive Innovations

  • Universal Signal Reactivity ($state, $derived): Reactivity is no longer confined to top-level .svelte script tags; it works in standard TypeScript classes and functions across .svelte.ts files.
  • Snippets replacing Slots ({#snippet} & @render): Snippets provide typed, parameterizable markup closures directly inside component bodies.
  • Explicit Two-Way Binding ($bindable()): Components declare explicitly whether a prop can be bound by parents with bind:prop.
Snippet: Reactive Runes Controller {#snippet} active
Counter ($state)

10

Multiplier

3x

Total ($derived)

30

Reactivity Stream:
Press Increment to dispatch reactive updates.