Skip to content

Commit c4bc59d

Browse files
mizulukodiakhq[bot]LadyBluenotes
authored
remove vague addition store setter filter (#1161)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Sarah <hello@sarahgerrard.me>
1 parent d5c820e commit c4bc59d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/routes/concepts/stores.mdx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,21 @@ 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 acts as a filter, receiving the old value and index, and gives you the 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)
356-
```
357357

358-
In addition to [`.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith), you can use other array methods like [`.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) to filter for the values that you need.
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)
364+
```
359365

360366
## Modifying objects
361367

0 commit comments

Comments
 (0)