Svelte
A compiler, not a framework — Svelte shifts the work to build time so shipped components run with near-zero runtime overhead.
19 pelajaran
Svelte
Mulai KursusGetting Started
- What is Svelte?Why Svelte is a compiler, not a runtime framework, and how that changes what shipping a component actually means.
- Setting Up a Svelte ProjectScaffolding a new Svelte 5 project with Vite and understanding the pieces it generates.
- Anatomy of a Svelte ComponentHow a .svelte file's script, markup, and style sections fit together into one component.
Runes & Reactivity
- Reactive State with $stateDeclaring reactive variables with the $state rune, Svelte 5's replacement for plain reactive `let`.
- Derived Values with $derivedComputing values from state that stay automatically in sync, without manually recalculating them yourself.
- Side Effects with $effectRunning code in response to state changes — logging, syncing to localStorage, or updating the DOM directly.
Props, Events & Binding
- Component Props with $propsDeclaring and destructuring the properties a component accepts, including defaults and rest props.
- Handling DOM EventsWiring up click, input, and other DOM events with Svelte's onevent attribute syntax.
- Two-Way Binding with bind:valueSyncing a form input's value directly to a state variable in both directions with the bind: directive.
- Component CommunicationPassing data down through props and sending updates back up through callback props.
Control Flow
- Conditional Rendering with {#if}Showing and hiding markup based on state using if, else if, and else blocks.
- Looping with {#each}Rendering lists from arrays, with keyed items so Svelte can update the DOM efficiently.
- Awaiting Promises in MarkupHandling pending, resolved, and error states of a promise directly in your template with {#await}.
Composition & Shared State
- Slots and SnippetsLetting a parent component inject markup into a child, from the classic <slot> to Svelte 5's snippets.
- Sharing State Across ComponentsExtracting $state into its own module so unrelated components can read and write the same value.
- Svelte StoresThe writable/readable store contract that predates runes, and where it still pulls its weight today.
Motion, Lifecycle & Best Practices
- Transitions and AnimationsAnimating elements in and out of the DOM with Svelte's built-in transition directives.
- Component Lifecycle with onMountRunning setup code once a component is mounted to the DOM, and cleaning it up when it's destroyed.
- Svelte Best Practices and Where to Go NextHabits that keep Svelte components small and predictable, and a look at SvelteKit as the next step.