# svelte-code-writer
> Expert guidance for writing proper Svelte 5 code with runes-based reactivity. Use when writing Svelte 5 components, migrating from Svelte 4, or troubleshooting Svelte 5 syntax. Covers $state, $derived, $effect, $props, $bindable, event handling, snippets, TypeScript integration, and common pitfalls.
- Author: SkepticMystic
- Repository: SkepticMystic/app-starter-template
- Version: 20260118103029
- Stars: 6
- Forks: 0
- Last Updated: 2026-02-06
- Source: https://github.com/SkepticMystic/app-starter-template
- Web: https://mule.run/skillshub/@@SkepticMystic/app-starter-template~svelte-code-writer:20260118103029
---
---
name: svelte-code-writer
description: Expert guidance for writing proper Svelte 5 code with runes-based reactivity. Use when writing Svelte 5 components, migrating from Svelte 4, or troubleshooting Svelte 5 syntax. Covers $state, $derived, $effect, $props, $bindable, event handling, snippets, TypeScript integration, and common pitfalls.
---
# Svelte 5 Code Writer
## Quick Reference
Svelte 5 uses **runes** (functions starting with `$`) for explicit reactivity:
```svelte
```
## Core Workflow
1. **Choose the right rune:**
- Computing from state? → Use `$derived`
- Managing reactive values? → Use `$state`
- Side effects (DOM, network, etc.)? → Use `$effect`
- Component props? → Use `$props`
2. **Apply the pattern** (see references below for details)
3. **Add TypeScript types** for props and state
## Key Patterns
### State: $state
```svelte
```
### Computed Values: $derived
**Use `$derived` for values computed from other state** (90% of cases):
```svelte
```
### Side Effects: $effect
**Use `$effect` only for side effects, not derivations, try to avoid reassign state in it:**
```svelte
```
### Props: $props
```svelte
```
### Two-Way Binding: $bindable
```svelte
```
## Event Handling
**Events are properties** (not directives):
```svelte
console.log(data)} />
```
## Snippets (Replacing Slots)
```svelte
{#snippet header()}
Title
{/snippet}
Default content here
{@render header?.()}
{@render children?.()}
```
## Common Pitfalls
**❌ Don't synchronize state with $effect:**
```svelte
let doubled = $state(0);
$effect(() => { doubled = count * 2; }); // Wrong!
```
**✅ Use $derived instead:**
```svelte
let doubled = $derived(count * 2); // Correct!
```
**❌ Don't mutate non-bindable props:**
```svelte
let {count} = $props(); count++; // Warning!
```
**✅ Use callbacks or $bindable:**
```svelte
let {(count, onIncrement)} = $props(); onIncrement(); // Correct!
```
## Migration from Svelte 4
| Svelte 4 | Svelte 5 |
| ------------------------ | ----------------------------------- |
| `let count = 0` | `let count = $state(0)` |
| `$: doubled = count * 2` | `let doubled = $derived(count * 2)` |
| `$: console.log(count)` | `$effect(() => console.log(count))` |
| `export let prop` | `let { prop } = $props()` |
| `on:click={handler}` | `onclick={handler}` |
| `` | `{@render children?.()}` |
## Detailed References
For comprehensive details, see:
- **[RUNES.md](references/RUNES.md)** - Complete runes reference with examples
- **[PATTERNS.md](references/PATTERNS.md)** - Component patterns and best practices
- **[PITFALLS.md](references/PITFALLS.md)** - Common mistakes and how to fix them
- **[MIGRATION.md](references/MIGRATION.md)** - Detailed migration guide from Svelte 4
- **[TYPESCRIPT.md](references/TYPESCRIPT.md)** - TypeScript patterns and typing
Load these references only when you need detailed information beyond the quick reference above.