Question · Svelte and SvelteKit course · Module 1: Introduction to Svelte
Adding to a Reactive Array
You have let warriors = $state(['Ragnar', 'Bjorn']). What happens after calling warriors.push('Ivar')?
Answer options
- Nothing - you still have to assign warriors = warriors
- The list on screen refreshes, because $state tracks changes inside the array
- Svelte throws an error - an array created with $state must not be changed
- Only the first item of the list changes
Show the answer
Correct answer:
- The list on screen refreshes, because $state tracks changes inside the array