npm.io
11.1.0 • Published 1 month ago

@primereact/hooks

Licence
SEE LICENSE IN LICENSE.md
Version
11.1.0
Deps
1
Size
115 kB
Vulns
0
Weekly
0

Cover

@primereact/hooks

General-purpose React hooks: filtering, input masking, hotkeys, local storage, media queries, lifecycle effects and more. These are the utilities PrimeReact is built on, published standalone for use in any React project.

No provider, no theme, no CSS.

npm install @primereact/hooks

Usage

Each hook has its own kebab-case subpath. The root entry re-exports all of them.

import { useFilter } from '@primereact/hooks/use-filter';

interface Customer {
    id: number;
    name: string;
    country: string;
}

export function CustomerList({ customers, query }: { customers: Customer[]; query: string }) {
    const { filteredData } = useFilter<Customer>({ data: customers, field: 'name', value: query });

    return (
        <ul>
            {filteredData.map((customer) => (
                <li key={customer.id}>{customer.name}</li>
            ))}
        </ul>
    );
}

Anything that touches the DOM is marked 'use client' internally, so server components can import these hooks without extra setup.

Component hooks such as useSelect or useDataTable are not part of this package; they live in @primereact/headless.

Documentation

License

Licensed under the PrimeUI License - Copyright (c) PrimeTek Informatics