KITFORMA · EDITORIAL ANSWER
How do I sort React state without corrupting its previous order?
KitForma editorial guide. Array.sort changes its receiver.
Step-by-step answer
setRows(old => [...old].sort((a,b) => a.score-b.score)), or toSorted where your target supports it. Copying the array does not clone the objects inside; editing a row also requires copying that row. Verify ascending and descending toggles and confirm another component holding the original array keeps its original order. Supply a numeric comparator for numeric fields.Sources and verification
Sources checked:
Scope: This editorial guide is based on the cited sources and tool behavior. A forum question or a query observed for our site does not establish market search volume, low competition, guaranteed rankings or inadequate answers elsewhere.
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.