sveltejs avatar

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-code

Installs 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] $derived is 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

More from sveltejs/ai-tools

All 2
1rivet-dev avatarrivetkit-client-reactrivet-dev/skillsRivetKit React client guidance. Use for React apps that connect to Rivet Actors with @rivetkit/react, create hooks with createRivetKit, or manage realtime state7.5Kskills.sh installs
2samber avatarfrontend-design-deslopsamber/cc-skillsProduce distinctive, non-generic UI and design applications well, working strategy-first. Identify the project (landing page, SaaS app, dashboard, ecommerce, pr5.8Kskills.sh installs
3giuseppe-trisciuoglio avatarreact-patternsgiuseppe-trisciuoglio/developer-kitProvides comprehensive React 19 patterns for Server Components, Server Actions, useOptimistic, useActionState, useTransition, concurrent features, Suspense boun4.9Kskills.sh installs
4softaworks avatarreact-devsoftaworks/agent-toolkitThis skill should be used when building React components with TypeScript, typing hooks, handling events, or when React TypeScript, React 19, Server Components a4.2Kskills.sh installs
5freshtechbro avatarreact-three-fiberfreshtechbro/claudedesignskillsBuild declarative 3D scenes with React Three Fiber (R3F) - a React renderer for Three.js. Use when building interactive 3D experiences in React applications wit4.1Kskills.sh installs
6giuseppe-trisciuoglio avatarnextjs-code-reviewgiuseppe-trisciuoglio/developer-kitProvides comprehensive code review capability for Next.js applications, validates Server Components, Client Components, Server Actions, caching strategies, meta3.9Kskills.sh installs