useComboboxData - Admin Components
The useComboboxData hook loads paginated and searchable options from the Medusa backend for a Combobox component. The Medusa Admin uses it in forms where the user selects a record, such as a product's collection or a region's countries.
Example#
Pass the hook's returned properties to the Combobox component:
1import { Combobox } from "@medusajs/dashboard/components"2import { useComboboxData } from "@medusajs/dashboard/hooks"3import { sdk } from "../lib/sdk"4 5const CollectionSelect = ({ value, onChange }) => {6 const collections = useComboboxData({7 queryKey: ["product_collections"],8 queryFn: (params) =>9 sdk.admin.productCollection.list(params),10 getOptions: (data) =>11 data.collections.map((collection) => ({12 label: collection.title,13 value: collection.id,14 })),15 })16 17 return (18 <Combobox19 value={value}20 onChange={onChange}21 options={collections.options}22 searchValue={collections.searchValue}23 onSearchValueChange={24 collections.onSearchValueChange25 }26 fetchNextPage={collections.fetchNextPage}27 disabled={collections.disabled}28 />29 )30}
The hook debounces the search value before sending the q query parameter to the Medusa backend, and it loads the next page of options when fetchNextPage is called.
To keep a record that the form already selected in the list, pass its ID to defaultValue or selectedValue. The hook then fetches that record separately and adds it to the beginning of options, even when the current page doesn't include it.
Parameters
The hook accepts an object with the following properties:
Returns#
Along with the following, the hook returns the rest of TanStack Query's useInfiniteQuery result.