4 ms·
Appreciate the response! You're right on Svelte v5; I just confirmed that Svelte's new runes are indeed reactive: let count = $state(0); function
by n2d4 3y ago
Appreciate the response! You're right on Svelte v5; I just confirmed that Svelte's new runes are indeed reactive:
let count = $state(0);
function increment() {
count += 1;
console.log(count + " + 1 = " + countPlusOne); // prints "1 + 1 = 2"
}
let countPlusOne = $derived(count + 1);
- anonzzzies 3y agoI never used svelte, so it’s probably a weird question, but how is increment() called?
- 698969 3y agoThe calling location has been omitted from the snippet. You don't need to do anything special to call it, just `increment()` wherever it's in scope. `<button on:click={() => increment()}>+</button>`
- lifeisstillgood 3y agocould you explain why this demonstrates svelte is reactive? What's the definition of reactive is I think my question and having a clear demo is useful - if I understood it it looks a useful piece code