Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update preferred non-mutating array methods #6810

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/content/learn/updating-arrays-in-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Here is a reference table of common array operations. When dealing with arrays i
| | avoid (mutates the array) | prefer (returns a new array) |
| --------- | ----------------------------------- | ------------------------------------------------------------------- |
| adding | `push`, `unshift` | `concat`, `[...arr]` spread syntax ([example](#adding-to-an-array)) |
| removing | `pop`, `shift`, `splice` | `filter`, `slice` ([example](#removing-from-an-array)) |
| replacing | `splice`, `arr[i] = ...` assignment | `map` ([example](#replacing-items-in-an-array)) |
| sorting | `reverse`, `sort` | copy the array first ([example](#making-other-changes-to-an-array)) |
| removing | `pop`, `shift`, `splice` | `toSpliced`, `filter`, `slice` ([example](#removing-from-an-array)) |
| replacing | `splice`, `arr[i] = ...` assignment | `with`, `map` ([example](#replacing-items-in-an-array)) |
| sorting | `reverse`, `sort` | `toReversed`, `toSorted`, or copy the array first ([example](#making-other-changes-to-an-array)) |

Alternatively, you can [use Immer](#write-concise-update-logic-with-immer) which lets you use methods from both columns.

Expand Down