Svelte 5 Runes: Interactive Reactive Counter Dashboard
Prompt
Create an interactive dashboard using Svelte 5 Runes ($state, $derived, $effect) that demonstrates reactive programming with multiple interconnected counters, derived values, and visual feedback.
CODE PREVIEW
AI rewrites this code based on your instructions. Preview is free; copy & download unlocked for ¥100.
AIとの対話に追加する一言
プロンプトと一緒にコピーして、AIがより正確に意図を汲み取れるようにします
このコードをそのまま使いたいので、CDNリンクも含めた完全なHTMLファイルとして出力してください。
初心者なので、各行にコメントを追加して、何をしているか説明してください。
このコードをWordPressのテーマに組み込む方法も教えてください。
動作確認済みのコードをお願いします。エラーが出る場合の対処法も含めて。
This interactive dashboard demonstrates the power of Svelte 5's new Runes system, which introduces a more explicit and flexible way to handle reactivity. The three main Runes used are:
$state: Creates reactive state variables. When these values change, any part of the component that depends on them automatically updates. In our dashboard, count, multiplier, and history are all state variables.
$derived: Creates computed values that automatically update when their dependencies change. The doubled, multiplied, and total values are derived from the state variables and update reactively without manual recalculation.
$effect: Runs side effects when dependencies change. Our effect tracks every 5th increment and adds it to the history array, demonstrating how to perform actions in response to state changes.
The dashboard features:
- Interactive counter with increment/decrement buttons
- Real-time multiplier slider that affects derived values
- Automatic history tracking using effects
- Visual feedback through animated transitions
- Glass-morphism design with modern UI elements
This example shows how Svelte 5 Runes make reactive programming more intuitive and powerful, with clear separation between state, derived values, and side effects.
Was this prompt helpful?
Comments
Comments appear after moderation
この記事が役に立ったら投げ銭で応援
Apple Pay / Google Pay / カード (Visa/Mastercard/JCB/Amex) / Link / Alipay / WeChat Pay 対応 · Stripeで安全に決済
開発者が選ぶ最強ツール集
運営者が毎日使っているツール・ガジェット 6選