
Svelte Core Bestpractices
Comprehensive reference for writing modern Svelte 5 code using runes instead of legacy patterns. Load this when working on any Svelte component to get guidance on reactivity ($state, $derived), proper use of $effect (sparingly), event handling, snippets over slots, and CSS scoping. The advice is opinionated in the right ways: it'll steer you toward $derived instead of effects for computed values, remind you to key your each blocks, and suggest context over shared modules for state. Especially helpful if you're migrating from Svelte 4 or keep reaching for old patterns like export let and $: statements. The $inspect.trace tip alone is worth having loaded when debugging reactive updates.
- skills.sh installs
- 12.1K
- GitHub stars
- 337
- last updated
- Aug 21, 2026
Install
$ npx -y skills add sveltejs/ai-tools --skill svelte-core-bestpractices --agent claude-codeInstalls into .claude/skills of the current project.
Files
$state
Only use the $state rune for variables that should be reactive — in other words, variables that cause an $effect, $derived or template expression to update. Everything else can be a normal variable.
Objects and arrays ($state({...}) or $state([...])) are made deeply reactive, meaning mutation will trigger updates. This has a trade-off: in exchange for fine-grained reactivity, the objects must be proxied, which has performance overhead. In cases where you're dealing with large objects that are only ever reassigned (rather than mutated), use $state.raw instead. This is often the case with API responses, for example.
$derived
To compute something from state, use $derived rather than $effect:
// do this
let square = $derived(num * num);
// don't do this
let square;
$effect(() => {
square = num * num;
});
[!NOTE]
$derivedis given an expression, not a function. If you need to use a function (because the expression is complex, for example) use$derived.by.
Deriveds are writable — you can assign to them, just like $state, except that they will re-evaluate when their expression changes.
Sponsors
Details
- Repository
- github.com/sveltejs/ai-tools
- Categories
- Frontend Development, Documentation, AI & Agent Building
- First seen
- Apr 16, 2026