Reactive Values
let count = 0;
$: if (count >= 10) {
alert('count is dangerously high!');
count = 0;
}
Svelte’s reactivity is triggered by assignments, using array methods like push
and splice
won’t automatically cause updates.
function addNumber() {
numbers = [...numbers, numbers.length + 1];
}