\n\n\n\n","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-1","name":"Reactive Declaration: Computed Values with $:","description":"Code example","text":"\n\n

{message}

\n","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-2","name":"Two-Way Data Binding: Form Input Binding","description":"Code example","text":"\n\n\n\n

Hello {name}, email: {email}

","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-3","name":"Event Handling: on: Directive","description":"Code example","text":"\n\n e.key === 'Enter' && addItem()} />\n\n","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-4","name":"Conditional Rendering: {#if} Block","description":"Code example","text":"\n\n\n\n{#if isVisible}\n

Visible content! Count: {count}

\n \n{:else}\n

Hidden

\n{/if}","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-5","name":"List Rendering: {#each} Block with Keys","description":"Code example","text":"\n\n\n\n","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-6","name":"Component Props: Child Component","description":"Code example","text":"\n\n
\n

{title}

\n

Count: {count}

\n \n
","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-7","name":"Parent Component: Passing Props","description":"Code example","text":"\n\n count++} />","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-8","name":"Lifecycle: onMount Hook","description":"Code example","text":"\n\n{#if loading}\n

Loading...

\n{:else}\n

{data.message}

\n{/if}","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-9","name":"Cleanup: onDestroy Hook","description":"Code example","text":"","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-10","name":"Transitions: Fade Effect","description":"Code example","text":"\n\n{#if visible}\n
\n

Fading content

\n
\n{/if}\n\n\n\n","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-11","name":"Transitions: Slide Effect","description":"Code example","text":"\n\n\n\n{#if isOpen}\n \n{/if}","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-12","name":"Animation: animate: Directive","description":"Code example","text":"\n\n\n","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-13","name":"Slots: Default Slot","description":"Code example","text":"\n\n","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-14","name":"Named Slots: Multiple Content Areas","description":"Code example","text":"\n\n
\n
\n \n
\n
\n \n
\n
\n \n
\n
","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-15","name":"Slot Props: Passing Data to Slot","description":"Code example","text":"\n\n","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-16","name":"Stores: Writable Store","description":"Code example","text":"\n\n// In component:\nimport { count } from './stores';\n\n

{$count}

\n","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-17","name":"Derived Stores: computed from other stores","description":"Code example","text":"\n\n

{$doubled}

","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-18","name":"Class Directive: Dynamic CSS Classes","description":"Code example","text":"\n\n\n\n","inLanguage":"javascript"},{"@type":"CreativeWork","@id":"https://yourcheatsheets.org/cheatsheets/svelte#snippet-19","name":"Style Directive: Inline Styles","description":"Code example","text":"\n\n
\n Styled text\n
","inLanguage":"javascript"}],"keywords":"Svelte cheat sheet, Svelte reactive programming, Svelte components, Svelte state management, SvelteKit tutorial, Svelte stores guide, Svelte lifecycle hooks, Svelte transitions, svelte, reactive-programming, components, state-management, web-development","about":[{"@type":"Thing","name":"svelte"},{"@type":"Thing","name":"reactive-programming"},{"@type":"Thing","name":"components"},{"@type":"Thing","name":"state-management"},{"@type":"Thing","name":"web-development"}]},{"@type":"ItemList","@id":"https://yourcheatsheets.org/cheatsheets/svelte#topics","name":"Core Concepts - Svelte Cheat Sheet DATA | Reactive Components + State Management Guide","numberOfItems":5,"itemListElement":[{"@type":"ListItem","position":1,"name":"Reactive Variables: Svelte State Binding","description":"Svelte reactive variables use let declarations with automatic reactivity tracking. The compiler transforms `let count = 0;` into reactive state without useState hooks. See reactive statements examples below.","url":"https://yourcheatsheets.org/cheatsheets/svelte#core-concepts"},{"@type":"ListItem","position":2,"name":"Svelte Reactive Statements: $: Syntax","description":"The $: label creates reactive declarations that re-run when dependencies change. Svelte component reactivity system automatically tracks dependencies for reactive programming.","url":"https://yourcheatsheets.org/cheatsheets/svelte#core-concepts"},{"@type":"ListItem","position":3,"name":"Component Lifecycle: onMount, onDestroy, beforeUpdate","description":"Svelte lifecycle hooks manage component mounting, destruction, and updates. onMount executes after component mounts, onDestroy runs cleanup, and beforeUpdate allows animations. Critical for Svelte component lifecycle patterns.","url":"https://yourcheatsheets.org/cheatsheets/svelte#core-concepts"},{"@type":"ListItem","position":4,"name":"Two-Way Data Binding: bind: Directive","description":"The bind: directive creates two-way bindings between component state and form inputs. `bind:value={variable}` eliminates boilerplate event handlers and manual state updates for Svelte form handling.","url":"https://yourcheatsheets.org/cheatsheets/svelte#core-concepts"},{"@type":"ListItem","position":5,"name":"Svelte Transitions & Animations: transition: Directive","description":"The transition: directive adds animations to DOM changes. Svelte animations include fade, slide, fly, scale, and draw. Essential for Svelte UI animation techniques without external libraries.","url":"https://yourcheatsheets.org/cheatsheets/svelte#core-concepts"}]},{"@type":"TechArticle","@id":"https://yourcheatsheets.org/cheatsheets/svelte#article","headline":"Svelte Cheat Sheet DATA | Reactive Components + State Management Guide","description":"Complete reference guide","image":[{"@type":"ImageObject","url":"https://yourcheatsheet.org/images/svelte-og","width":1200,"height":630},{"@type":"ImageObject","url":"https://yourcheatsheet.org/images/svelte-og","width":800,"height":800}],"author":{"@id":"https://yourcheatsheet.org/author/david-nguyen"},"publisher":{"@id":"https://yourcheatsheet.org/about"},"inLanguage":"en-US","isAccessibleForFree":true,"keywords":"Svelte cheat sheet, Svelte reactive programming, Svelte components, Svelte state management, SvelteKit tutorial, Svelte stores guide, Svelte lifecycle hooks, Svelte transitions, svelte, reactive-programming, components, state-management, web-development","speakable":{"@type":"SpeakableSpecification","cssSelector":["#top","#quick-start","#when-to-use","#core-concepts","#snippets","#master-commands","#production-examples","#production-fixes","#pitfalls","#troubleshooting","#elite-pro-hack","#workflows","#benchmark","#resources"]},"potentialAction":[{"@type":"ReadAction","target":{"@type":"EntryPoint","urlTemplate":"https://yourcheatsheets.org/cheatsheets/svelte"}},{"@type":"DownloadAction","name":"Download PDF","target":{"@type":"EntryPoint","urlTemplate":"https://yourcheatsheets.org/downloads/svelte.pdf"}}]},{"@type":"BreadcrumbList","@id":"https://yourcheatsheets.org/cheatsheets/svelte#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://yourcheatsheet.org"},{"@type":"ListItem","position":2,"name":"Frontend-Development","item":"https://yourcheatsheet.org/categories/Frontend-Development"},{"@type":"ListItem","position":3,"name":"Svelte Cheat Sheet DATA | Reactive Components + State Management Guide","item":"https://yourcheatsheets.org/cheatsheets/svelte"}]}]}

Quick Start with Svelte

Production-ready compilation flags and build commands

Svelte Component Basics: QUICK START (5s)

Copy → Paste → Live

npm create vite@latest myapp -- --template svelte
cd myapp
npm install
npm run dev
$
Vite dev server running at http://localhost:5173. Learn more in Svelte SvelteKit setup section
⚔ 5s Setup

When to Use Svelte

Decision matrix per scegliere la tecnologia giusta

IDEAL USE CASES

  • Building interactive UIs with minimal JavaScript boilerplate using Svelte reactive statements

  • Creating lightweight single-page applications where bundle size matters with Svelte compilation

  • Rapid prototyping with Svelte component lifecycle and two-way data binding out of the box

AVOID FOR

  • Large enterprise teams requiring extensive tooling ecosystem (use React instead)

  • Projects needing mature debugging tools and massive community support for Svelte troubleshooting

  • Legacy browser support requirements below ES6 (Svelte targets modern browsers)

Core Concepts of Svelte

Production-ready compilation flags and build commands

#1

Reactive Variables: Svelte State Binding

Svelte reactive variables use let declarations with automatic reactivity tracking. The compiler transforms `let count = 0;` into reactive state without useState hooks. See reactive statements examples below.

āœ“ Solution
Use direct assignment: `items = [...items, newItem]` instead of `items.push(newItem)`
+40% performance vs direct mutation detection
#2

Svelte Reactive Statements: $: Syntax

The $: label creates reactive declarations that re-run when dependencies change. Svelte component reactivity system automatically tracks dependencies for reactive programming.

āœ“ Solution
Wrap computed properties in `$: derived = reactive_var * 2`
+60% cleaner code vs manual dependency arrays
#3

Component Lifecycle: onMount, onDestroy, beforeUpdate

Svelte lifecycle hooks manage component mounting, destruction, and updates. onMount executes after component mounts, onDestroy runs cleanup, and beforeUpdate allows animations. Critical for Svelte component lifecycle patterns.

Lifecycle hooks execute in <1ms on modern hardware
#4

Two-Way Data Binding: bind: Directive

The bind: directive creates two-way bindings between component state and form inputs. `bind:value={variable}` eliminates boilerplate event handlers and manual state updates for Svelte form handling.

āœ“ Solution
Export props in child component: `export let myProp = '';`
#5

Svelte Transitions & Animations: transition: Directive

The transition: directive adds animations to DOM changes. Svelte animations include fade, slide, fly, scale, and draw. Essential for Svelte UI animation techniques without external libraries.

+80% UX perceived performance with proper transitions