Skip to content

Commit 690cefa

Browse files
committed
Update preferred array methods to include ES2023 non-mutating methods: toSpliced, with, toReversed, toSorted
1 parent 9c4bc28 commit 690cefa

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/content/learn/updating-arrays-in-state.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ Here is a reference table of common array operations. When dealing with arrays i
2626

2727
| | avoid (mutates the array) | prefer (returns a new array) |
2828
| --------- | ----------------------------------- | ------------------------------------------------------------------- |
29-
| adding | `push`, `unshift` | `concat`, `[...arr]` spread syntax ([example](#adding-to-an-array)) |
30-
| removing | `pop`, `shift`, `splice` | `filter`, `slice` ([example](#removing-from-an-array)) |
31-
| replacing | `splice`, `arr[i] = ...` assignment | `map` ([example](#replacing-items-in-an-array)) |
32-
| sorting | `reverse`, `sort` | copy the array first ([example](#making-other-changes-to-an-array)) |
33-
29+
| removing | `pop`, `shift`, `splice` | `toSpliced`, `filter`, `slice` ([example](#removing-from-an-array)) |
30+
| replacing | `splice`, `arr[i] = ...` assignment | `with`, `map` ([example](#replacing-items-in-an-array)) |
31+
| sorting | `reverse`, `sort` | `toReversed`, `toSorted`, or copy the array first ([example](#making-other-changes-to-an-array)) |
3432
Alternatively, you can [use Immer](#write-concise-update-logic-with-immer) which lets you use methods from both columns.
3533

3634
<Pitfall>

0 commit comments

Comments
 (0)