js-tosorted-immutable
Use toSorted() instead of sort() to avoid mutating arrays. Apply when sorting arrays that are React props, state, or otherwise shared/referenced elsewhere.
Installation
Pick a client and clone the repository into its skills directory.
Installation
About this skill
Use toSorted() instead of sort() to avoid mutating arrays. Apply when sorting arrays that are React props, state, or otherwise shared/referenced elsewhere.
How to use
Zainstaluj skill w swoim projekcie Claude lub Copilot, dodając plik js-tosorted-immutable do katalogu skills.
Gdy piszesz kod React z sortowaniem tablic, skill automatycznie wykryje użycie sort() na tablicach pochodzących z propsów, stanu lub zmiennych współdzielonych między komponentami.
Zaakceptuj sugestię skill'u, aby zamienić sort() na toSorted(). Zmiana jest prosta: zamiast users.sort((a, b) => ...) użyj users.toSorted((a, b) => ...).
Jeśli pracujesz w starszym środowisku, które nie wspiera toSorted(), skill zasugeruje fallback z operatorem spread: [...items].sort((a, b) => ...).
Sprawdź, czy Twoja przeglądarka lub wersja Node.js obsługuje toSorted() — dostępny jest w Chrome 110+, Safari 16+, Firefox 115+ i Node.js 20+. Dla starszych wersji używaj fallbacku.
Pamiętaj, że skill dotyczy również innych immutable metod tablic: toReversed() zamiast reverse() oraz toSpliced() zamiast splice(). Stosuj je konsekwentnie w całym kodzie React.