Right way to track changes in reactive arrays or js objects? #15767
-
Hi, I'm getting started with Svelte 5 and I've been struggling on finding the proper way to track reactive arrays of objects and objects. I'll show the first approach I tried, I read that this is not expected to work, and instead I should be accessing each property of each element in the array to be able to track it's single reactivity.
But what happens if I want to be able to execute some code if any of all the fields of all the elements changed? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
What code are you trying to run? If you access relevant data on the object, the effect will run automatically. It should be relatively rare that code is supposed to run without even looking at the data whose change is triggering it. (Also, the category of this should probably be "Q&A".) |
Beta Was this translation helpful? Give feedback.
If you save the data, you have to read the data, reading the data creates
$effect
dependencies on the data, i.e. the$effect
will trigger if you actually implement the logic you intend to implement.