use-sorted
Sorted copy of a reactive array; the source is never mutated.
| Package | @vizejs/composable/use-sorted |
| Own the source | vize lib pull composable:use-sorted |
| Runtime exports | useSorted |
| Gzip budget | 512 B |
Usage
import { useSorted } from "@vizejs/composable/use-sorted";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
useSorted |
state | experimental | safe | stable | none | web, server, worker, native, desktop, terminal | — | — |
API
useSorted
Sorted copy of a reactive array; the source is never mutated. Numbers, bigints, strings, and dates sort in natural ascending order by default (numerically, unlike Array.prototype.sort); any other item type requires a comparator. The sort is stable. Pure derived state: SSR-safe and nothing to dispose.
function useSorted<Item extends NaturallyOrdered>( source: MaybeRefOrGetter<readonly Item[]>, compare?: SortComparator<Item>, ): ComputedRef<Item[]>
const ranked = useSorted(players, (a, b) => b.score - a.score);
const ascending = useSorted([10, 9, 100]); // [9, 10, 100]
useSorted
function useSorted<Item>( source: MaybeRefOrGetter<readonly Item[]>, compare: SortComparator<Item>, ): ComputedRef<Item[]>
useSorted
function useSorted( source: MaybeRefOrGetter<readonly NaturallyOrdered[]>, compare: SortComparator<NaturallyOrdered> = naturalOrder, ): ComputedRef<NaturallyOrdered[]>