About svelte5-best-practices
A reference skill for applying Svelte 5 patterns across reactivity, components, events, TypeScript, SvelteKit, migration, and performance. It helps developers use current conventions and avoid common mistakes.
Key features
- 01Runes and reactive state patterns
- 02Snippets and component props
- 03Event and callback conventions
- 04TypeScript and generic components
- 05SvelteKit and performance guidance
- 06Svelte 4 migration notes
Use cases
- 01Building Svelte 5 components
- 02Migrating Svelte 4 code
- 03Implementing SvelteKit loading and form actions
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ ejirocodes/ agent-skills --skill svelte5-best-practicesAfter installing, type/svelte5-best-practicesin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
references/events.mdmigration.mdperformance.mdrunes.mdsnippets.mdsveltekit.mdtypescript.mdDetails
From the project READMESvelte 5 Best Practices
Quick Reference
| Topic | When to Use | Reference |
|---|---|---|
| Runes | $state, $derived, $effect, $props, $bindable, $inspect | runes.md |
| Snippets | Replacing slots, {#snippet}, {@render} | snippets.md |
| Events | onclick handlers, callback props, context API | events.md |
| TypeScript | Props typing, generic components | typescript.md |
| Migration | Svelte 4 to 5, stores to runes | migration.md |
| SvelteKit | Load functions, form actions, SSR, page typing | sveltekit.md |
| Performance | Universal reactivity, avoiding over-reactivity, streaming | performance.md |
Essential Patterns
Reactive State
<script>
let count = $state(0); // Reactive state
let doubled = $derived(count * 2); // Computed value
</script>
Component Props
<script>
let { name, count = 0 } = $props();
let { value = $bindable() } = $props(); // Two-way binding
</script>
Snippets (replacing slots)
<script>
let { children, header } = $props();
</script>
{@render header?.()}
{@render children()}
Event Handlers
<!-- Svelte 5: use onclick, not on:click -->
<button onclick={() => count++}>Click</button>
Callback Props (replacing createEventDispatcher)
<script>
let { onclick } = $props();
</script>
<button onclick={() => onclick?.({ data })}>Click</button>
Common Mistakes
- Using
letwithout$state- Variables are not reactive without$state() - Using
$effectfor derived values - Use$derivedinstead - Using
on:clicksyntax - Useonclickin Svelte 5 - Using
createEventDispatcher- Use callback props instead - Using
<slot>- Use snippets with{@render} - Forgetting
$bindable()- Required forbind:to work - Setting module-level state in SSR - Causes cross-request leaks
- Sequential awaits in load functions - Use
Promise.allfor parallel requests
Comments
Markdown supported