react.dev icon indicating copy to clipboard operation
react.dev copied to clipboard

[Suggestion]: use toSorted and toReversed for the examples in Updating Array in State Page

Open Snaylaker opened this issue 1 year ago • 2 comments

Summary

Update this section Updating arrays without mutation by adding toReversed() and toSorted() instead of suggestion cloning the array and mutating it.

Page

https://react.dev/learn/updating-arrays-in-state

Details

Since toReversed() and toSorted() have been added to Javascript, should the docs reflect the changes and remove the section about mutating the array before sorting and reversing?

Or does it stay just to give an example of cloning before mutating an array ?

Snaylaker avatar Aug 29 '24 22:08 Snaylaker

I would like to work on this issue

BrianWoolfolk avatar Sep 18 '24 21:09 BrianWoolfolk

You can see my PR #7174 for this issue.

I considered appropriate to also add a Note block regarding the similarities between the new methods and the spread syntax.

BrianWoolfolk avatar Sep 19 '24 01:09 BrianWoolfolk