# useCollator
> Provides a cached Intl.Collator instance for locale-sensitive string comparison.

Provides localised string collation for the current locale. It automatically updates when the locale changes and uses performance-optimised caching.
For detailed information about collation options and behaviour, see the <Link isExternal href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator">Intl.Collator documentation</Link>.

## Import

```js
import { useCollator } from '@volue/wave-react';
```

## Example

```jsx
() => {
  const deCollator = useCollator('de');
  const noCollator = useCollator('no');

  const fruits = ['erdbeere', 'äpfel', 'banane', 'orangen', 'aprikose'];
  const germanSorted = [...fruits].sort((a, b) => deCollator.compare(a, b));
  const norwegianSorted = [...fruits].sort((a, b) => noCollator.compare(a, b));

  return (
    <Flex flow="column">
      <Flex flow="column" gap="none">
        <Text fontWeight="semibold">{'Original order:'}</Text>
        <Text>{fruits.join(', ')}</Text>
      </Flex>
      <Flex flow="column" gap="none">
        <Text fontWeight="semibold">{'Sorted (de locale):'}</Text>
        <Text>{germanSorted.join(', ')}</Text>
      </Flex>
      <Flex flow="column" gap="none">
        <Text fontWeight="semibold">{'Sorted (no locale):'}</Text>
        <Text>{norwegianSorted.join(', ')}</Text>
      </Flex>
    </Flex>
  );
};
```

---

## API reference

### Arguments

| Name      | Type                   | Default | Description                                                                  | Required |
| --------- | ---------------------- | ------- | ---------------------------------------------------------------------------- | -------- |
| `locale`  | `string`               | `—`     | The locale to use for collation (e.g. "en", "de", "fr").                     | Yes      |
| `options` | `Intl.CollatorOptions` | `—`     | Configuration options for the `Intl.Collator` (e.g. sensitivity, caseFirst). |          |

### Returns

`Intl.Collator` — A cached collator instance for the given locale and options.
