You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/routes/concepts/stores.mdx
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -253,8 +253,10 @@ Instead of relying on discovering individual indices, path syntax introduces sev
253
253
254
254
### Appending new values
255
255
256
-
To append new values to an array in a store, use the setter function with the spread operator (`...`) to create a new array that includes the existing items and the new ones.
257
-
For appending a single element, you can instead leverage the "path syntax" by specifying the array’s length as the index to set.
256
+
To append values to an array in a store, use the setter function with the spread operator (`...`) or the path syntax. Both methods add an element to the array but differ in how they modify it and their reactivity behavior.
257
+
258
+
The spread operator creates a new array by copying the existing elements and adding the new one, effectively replacing the entire `store.users` array.
259
+
This replacement triggers reactivity for all effects that depend on the array or its properties.
The path syntax adds the new element by assigning it to the index equal to `store.users.length`, directly modifying the existing array.
274
+
This triggers reactivity only for effects that depend on the new index or properties like `store.users.length`, making updates more efficient and targeted.
0 commit comments