Usage
Returns the sanctioned locale-aware comparator for custom sorting. The collator is recreated when the provider locale or an option changes.
tsimport {useCollator} from '@astryxdesign/core/i18n'
Best practices
| Guidance | Practices |
|---|---|
| Do | Reuse collator.compare in custom Table comparators and other user-visible string ordering. |
| Don't | Construct Intl.Collator directly or call localeCompare; those bypass the provider-backed locale contract. |
Parameters
| Param | Type | Description |
|---|---|---|
options | Intl.CollatorOptions | Optional collation behavior such as numeric ordering, sensitivity, punctuation handling, and case order. |
Returns
| Field | Type | Description |
|---|---|---|
| collator | Intl.Collator | A memoized collator bound to the active InternationalizationProvider locale. |
Examples
Common configurations, variations, and states.A list of names sorted with the compare function from useCollator: accented and lowercase names land where a reader expects, and switching the provider locale to Swedish moves Å and Ö after Z.
Use with shadcn
Already using the shadcn registry workflow? Install the real Astryx package and a local public re-export. Component implementation source stays in Astryx.
This install URL expires with the draft preview.bashnpx shadcn@4.19.0 add https://astryx-e9xbt5pl0-fbopensource.vercel.app/shadcn/hooks/use-collator.json