Create Svelte components with reactivity and stores
✓Works with OpenClaudeYou are a Svelte developer. The user wants to create reactive Svelte components that use stores for shared state management.
What to check first
- Verify SvelteKit or Vite+Svelte is installed:
npm list svelte - Check if you have a
src/libdirectory for reusable components - Confirm
svelte/storeis available in your project dependencies
Steps
- Create a new
.sveltefile insrc/lib/components/with a descriptive name (e.g.,Counter.svelte) - Define reactive variables using the
letdeclaration at the top level of the script block - Use
$:reactive statements to automatically recalculate derived values when dependencies change - Create or import a Svelte store using
writable(),readable(), orderived()fromsvelte/store - Subscribe to stores in your component using the
$prefix (auto-subscription syntax) - Bind form inputs to reactive variables with
bind:valueto create two-way binding - Export props using
export letstatements so parent components can pass data down - Export functions or reactive values so parent components can access them via
bind:this
Code
<script>
import { writable, derived } from 'svelte/store';
// Component props
export let title = 'Counter';
export let initialCount = 0;
// Reactive variables
let localCount = initialCount;
let inputValue = '';
// Create a store for shared state
const count = writable(initialCount);
const message = writable('Ready');
// Derived store (computed value)
const doubled = derived(count, $count => $count * 2);
// Reactive statement: runs when localCount changes
$: if (localCount > 10) {
message.set('Count is high!');
}
// Functions to modify state
function increment() {
localCount += 1;
count.set(localCount);
}
function decrement() {
localCount -= 1;
count.set(localCount);
}
function reset() {
localCount = initialCount;
count.set(initialCount);
message.set('Ready');
}
function handleInput(event) {
inputValue = event.target.value;
}
</script>
<div class="counter-container">
<h2>{title}</h2>
<p>Current: {localCount}</p>
<p>Doubled: {$doubled}</p>
<p class="message">{$message}</p>
<div class="button-group">
<button on:click={increment}>+</button>
<button on:click={decrement}>−</button>
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Svelte Skills
Other Claude Code skills in the same category — free to download.
SvelteKit
Scaffold SvelteKit app with routing and load functions
Svelte Store
Build Svelte stores for shared state management
Svelte Actions
Create Svelte actions for reusable DOM behavior
Svelte Testing
Test Svelte components with Vitest and Testing Library
Want a Svelte skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.