Custom React Hook

useApiOptions

useApiOptions powers SelectApiField and remote autocompletes. It handles debounced search queries, infinite scroll loading, caching, and mapping backend keys to { key, value } options.

Debounced search queries (default: 400ms)
Infinite scroll pagination (loadingMore state)
Custom transformation via onFormatData callback

Hook Parameters

PropertyTypeDefaultDescription
apiUrlstring—Remote endpoint to query.
debounceMsnumber400Search debounce delay in milliseconds.
labelPathstring"value"JSON key for option label.
valuePathstring"key"JSON key for option value.

Return Object Properties

PropertyTypeDefaultDescription
optionsOptionType[]—Formatted array of { key, value } options.
loadingboolean—Initial query loading state.
loadingMoreboolean—Loading state during infinite scroll.
onSearch(text: string) => void—Search callback to trigger debounced query.

Practical Hook Examples & Workflows

Explore quickstart usage, full parameter integration, and production data workflows.

Standalone Remote Select with useApiOptions: Hook integration with Ant Design's standard Select component.
useApiOptions.select.tsxtsx
1import React from "react";
2import { useApiOptions } from "antd-dynamic-ui";
3import { Select } from "antd";
4
5export default function DepartmentSelect() {
6 const { options, loading, onSearch } = useApiOptions({
7 apiUrl: "/api/v1/departments",
8 labelPath: "deptName",
9 valuePath: "deptId",
10 debounceMs: 300,
11 });
12
13 return (
14 <Select
15 showSearch
16 placeholder="Select department"
17 loading={loading}
18 onSearch={onSearch}
19 options={options.map((o) => ({ label: o.value, value: o.key }))}
20 className="w-72"
21 />
22 );
23}