Skip to content

Commit b09489a

Browse files
committed
// Update users with usernames starting with "t"
1 parent 42a2f55 commit b09489a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/routes/concepts/stores.mdx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,20 @@ setStore("users", 3, "loggedIn" , (loggedIn) => !loggedIn)
347347

348348
### Filtering values
349349

350-
In scenarios where you want to update elements in an array based on a specific condition, you can pass a function as an argument.
351-
This function will act as a filter, allowing you to select elements that satisfy the condition.
352-
It receives the old value and index as arguments, providing the flexibility to make conditional updates.
350+
To update elements in an array based on specific conditions, you can pass a function as an argument.
351+
This function will act as a filter, It receives the old value and index, giving you flexibility to apply logic that targets specific cases.
352+
This might include using methods like `.startsWith()`, `includes()`, or other comparison techniques to determine which elements should be updated.
353353

354354
```jsx
355+
// update users with username that starts with "t"
355356
setStore("users", (user) => user.username.startsWith("t"), "loggedIn", false)
357+
358+
// update users with location "Canada"
359+
setStore("users", (user) => user.location == "Canada" , "loggedIn", false)
360+
361+
// update users with id 1, 2 or 3
362+
let ids = [1,2,3]
363+
setStore("users", (user) => ids.includes(user.id) , "loggedIn", false)
356364
```
357365

358366
## Modifying objects

0 commit comments

Comments
 (0)