{ greeting }

Count: { count } (doubled: { doubled } )

$state with Objects and Arrays
Back to articles
Svelte 5 Has a Free API — Here's How to Use Runes for Fine-Grained Reactivity

Svelte 5 Has a Free API — Here's How to Use Runes for Fine-Grained Reactivity

via Dev.to JavaScriptAlex Spinov

Svelte 5 introduces Runes — a new reactivity system that is more explicit, composable, and powerful. Svelte compiles your components into minimal JavaScript with no virtual DOM overhead. Getting Started npx sv create my-app cd my-app npm install npm run dev Runes — The New Reactivity <script> // $state — reactive state let count = $state ( 0 ); let name = $state ( " World " ); // $derived — computed values let doubled = $derived ( count * 2 ); let greeting = $derived ( `Hello, ${ name } !` ); // $effect — side effects $effect (() => { console . log ( `Count changed to ${ count } ` ); document . title = `Count: ${ count } ` ; }); function increment () { count ++ ; } </script> <h1> { greeting } </h1> <p> Count: { count } (doubled: { doubled } ) </p> <button onclick= { increment } > +1 </button> <input bind:value= { name } /> $state with Objects and Arrays <script> let todos = $state ([ { id : 1 , text : " Learn Svelte 5 " , done : false }, { id : 2 , text : " Build an app " , done : fals

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
2 views

Related Articles