Data sources
For local data, pass an array to data. The default grid searches column field values and sorts columns marked sortable. Local data is unpaginated by default; providing a custom pagination renderer enables local pagination.
For remote data, supply dataSource. It receives a one-based page, page size, search string and optional sort state. Return rows for that page and the total matching record count, not the page length.
import type { DataSourceFn } from 'react-lookup-select';
const loadParts: DataSourceFn<Part> = async query => { const params = new URLSearchParams({ page: String(query.page), pageSize: String(query.pageSize), search: query.search ?? '', sortBy: query.sortBy ?? '', sortDir: query.sortDir ?? '', }); const response = await fetch('/api/parts?' + params); if (!response.ok) throw new Error('Unable to load parts'); return response.json(); // { rows: Part[], total: number }};Use the callback as dataSource={loadParts}. Keep its identity stable (define it outside the component or use useCallback). Search is debounced for 300 ms; search and sort changes reset the page. Responses from an obsolete request are ignored, but the library does not abort the underlying fetch.
Try remote pagination
Section titled “Try remote pagination”Search by part or SKU, select records, then apply. Cancel leaves the previous value unchanged.
[]
Failure and retry
Section titled “Failure and retry”This mock fails the first request. Open the picker, use Retry, and continue selecting.
Search by part or SKU, select records, then apply. Cancel leaves the previous value unchanged.
[]
The examples simulate an endpoint locally. In production validate query parameters server-side, limit page size, and apply authorization and deterministic ordering before paging.