fix: Cannot sort observable array

This commit is contained in:
Tom Moor committed 2026-09-05 09:13:46 +09:00
1 parent 21df3db7a6
commit d40bfc6f09
1 file changed
+4 -3
+4 -3
View File
@@ -40,9 +40,10 @@ function naturalSortBy<T extends object>(
})
: sorter;
return items.sort((a: T, b: T) =>
sort(getSortByField(a, key), getSortByField(b, key))
);
// Sort a copy, `items` may be an observable array which cannot be sorted in place.
return items
.slice()
.sort((a: T, b: T) => sort(getSortByField(a, key), getSortByField(b, key)));
}
export default naturalSortBy;