Options
When passing options into a combobox they have the type:
options: Array<Option | string | number | null | undefined>
Where Option
has the type:
type Option = {
label?: string;
name?: string;
title?: string;
disabled?: boolean;
group?: string;
value?: any;
id?: string;
html?: object;
description?: string | ReactElement;
hint?: string | ReactElement;
};
mapOption
If your options don't match this signature you can use the mapOption
to map them to the signature.
mapOption: (option: any) => Option
Example:
const [value, setValue] = useState(initialValue);
const mapOption = useCallback(({ name, deleted }) => {
return {
label: name,
disabled: deleted,
};
}, []);
<Select
options={options}
value={value}
setValue={setValue}
mapOption={mapOption}
/>;
Option identity
When determining which option is selected the "identity" of the option is compared.
The identity is calculated by the equivalent of:
String(option?.value ?? option?.id ?? option?.label ?? option ?? '');