Quick start
Installation
Section titled “Installation”npm i react-lookup-selectCheck the changelog and published versions to ensure the documented API is available in your installed version. The examples on this site follow the checked-out source.
Import the stylesheet once in your application. Without it, the default trigger, grid and modal will not have their intended styling.
import { useState } from 'react';import { LookupSelect } from 'react-lookup-select';import type { ColumnDef, IdText } from 'react-lookup-select';import 'react-lookup-select/styles.css';
type Part = { id: number; name: string; stock: number };
const parts: Part[] = [ { id: 1, name: 'Linear bearing', stock: 7 }, { id: 2, name: 'Drive belt', stock: 24 },];
const columns: ColumnDef<Part>[] = [ { key: 'name', title: 'Part', sortable: true }, { key: 'stock', title: 'Stock' },];
export default function PartPicker() { const [selection, setSelection] = useState<IdText | null>(null); return ( <LookupSelect data={parts} columns={columns} mapper={{ getId: row => row.id, getText: row => row.name }} valueFormat="id-text" value={selection} onChange={setSelection} /> );}mapper.getId must return a stable, unique string or number for each record. The display text does not need to be unique. Omitting mode defaults to single selection; omitting returnShape defaults to an ID/text pair.
Search by part or SKU, select records, then apply. Cancel leaves the previous value unchanged.
null
Open the picker, select a row and apply. To allow multiple values, use mode="multiple" and store an IdText[] instead. See value formats for the distinction between inputs and outputs.