Svelte5 Web Development Question About Runes
In a separate .svelte.js
file I have
export let allQuestionsRune = $state([new ObjectWithStringProperty("hi")])
Then in a button onClick
method in some +page file I am doing
allQuestionsRune[0].stringProperty = "new string"
Then in a separate svelte component I am referencing this exact property as such:
<p>{allQuestionsRune[0].stringProperty}</p>
Expected behavior: I see a "hi" on the screen. Then I click the button, and I should see the "hi" change to "new string".
Actual Result: I see a "hi" on the screen. And that's it. The button is not updating at all. I thought this was supposed to be reactive ... I don't get what is going on. I have verified that the onClick
method is being fired correctly.
Excerpt of some svelte documentation I don't fully understand ... If $state is used with an array or a simple object, the result is a deeply reactive state proxy. ... Perhaps this is a hint ? I don't really understand this excerpt at all.
What am I missing? Why is my rune not behaving as I expect?