# useCount

*Category:* Utilities
*Section:* Data aggregation hooks
*Source:* https://uikit.developers.rio.cloud/#/utilities/useCount
*Captured:* 2026-04-27T14:59:46.251Z

useCount is a utility hook for counting how many objects in a list contain a specific value or match a custom condition at a given property path. It supports exact value matching (e.g. true, 0, 'PENDING') or predicate-based logic using a match function. By default, all values that are not null or undefined are counted.

## useCount

### Example: Example 1

Deliveries marked as delivered: 3
Deliveries marked as not delivered: 2
Deliveries with status "PENDING": 2
Deliveries with quantity 0: 2
Deliveries with a written note: 2
Deliveries with at least one item: 3

#### React (tsx)

```tsx
import useCount from '@rio-cloud/rio-uikit/useCount';

const deliveries = [
    {
        id: 'D-001',
        delivered: true,
        status: 'PENDING',
        quantity: 0,
        notes: '',
        items: [],
    },
    {
        id: 'D-002',
        delivered: false,
        status: 'CONFIRMED',
        quantity: 20,
        notes: 'Customer confirmed by phone.',
        items: [1, 2],
    },
    {
        id: 'D-003',
        delivered: true,
        status: 'CANCELLED',
        quantity: 0,
        notes: null,
        items: [],
    },
    {
        id: 'D-004',
        delivered: false,
        status: 'PENDING',
        quantity: 10,
        notes: 'Leave at front desk.',
        items: [1],
    },
    {
        id: 'D-005',
        delivered: true,
        status: 'CONFIRMED',
        quantity: 5,
        notes: '',
        items: [1, 2, 3],
    },
];

export default () => {
    const countDelivered = useCount(deliveries, 'delivered', { equals: true });
    const countUndelivered = useCount(deliveries, 'delivered', { equals: false });

    const countPendingStatus = useCount(deliveries, 'status', { equals: 'PENDING' });

    const countQuantityZero = useCount(deliveries, 'quantity', { equals: 0 });

    const countWithNotes = useCount(deliveries, 'notes', {
        match: val => typeof val === 'string' && val.trim().length > 0,
    });

    const countWithItems = useCount(deliveries, 'items', {
        match: val => Array.isArray(val) && val.length > 0,
    });

    return (
        <table>
            <tbody>
                <tr>
                    <td>Deliveries marked as delivered:</td>
                    <td className='text-right width-20'>{countDelivered}</td>
                </tr>
                <tr>
                    <td>Deliveries marked as not delivered:</td>
                    <td className='text-right width-20'>{countUndelivered}</td>
                </tr>
                <tr>
                    <td>Deliveries with status "PENDING":</td>
                    <td className='text-right width-20'>{countPendingStatus}</td>
                </tr>
                <tr>
                    <td>Deliveries with quantity 0:</td>
                    <td className='text-right width-20'>{countQuantityZero}</td>
                </tr>
                <tr>
                    <td>Deliveries with a written note:</td>
                    <td className='text-right width-20'>{countWithNotes}</td>
                </tr>
                <tr>
                    <td>Deliveries with at least one item:</td>
                    <td className='text-right width-20'>{countWithItems}</td>
                </tr>
            </tbody>
        </table>
    );
};
```

#### HTML (html)

```html
<table>
    <tbody>
        <tr>
            <td>Deliveries marked as delivered:</td>
            <td class="text-right width-20">3</td>
        </tr>
        <tr>
            <td>Deliveries marked as not delivered:</td>
            <td class="text-right width-20">2</td>
        </tr>
        <tr>
            <td>Deliveries with status "PENDING":</td>
            <td class="text-right width-20">2</td>
        </tr>
        <tr>
            <td>Deliveries with quantity 0:</td>
            <td class="text-right width-20">2</td>
        </tr>
        <tr>
            <td>Deliveries with a written note:</td>
            <td class="text-right width-20">2</td>
        </tr>
        <tr>
            <td>Deliveries with at least one item:</td>
            <td class="text-right width-20">3</td>
        </tr>
    </tbody>
</table>
```

#### Props: Options for the `useCount` hook

### Options for the `useCount` hook

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| items | unknown[] | — | The array of objects to evaluate. |
| path | string | — | Dot-separated path to the field that should be checked in each object. |
| options | object | — | Optional configuration for counting logic. |
| └equals | unknown | — | The exact value to match against. Only values that strictly equal this will be counted. Ignored if `match` is defined. |
| └match | (value: unknown) => boolean | — | Custom predicate function that determines whether a value should be counted. Overrides `equals` if defined. |

#### Props: Return value of the `useCount` hook

### Return value of the `useCount` hook

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| count | number | — | The number of objects where the target value matches the given condition. |