feat(combo): debounce only with address / autocomplete binded on API

This commit is contained in:
Colin Darie 2022-10-10 21:09:23 +02:00
parent 5ab880aae7
commit 2d7eca9dd2
2 changed files with 4 additions and 1 deletions

View file

@ -25,6 +25,7 @@ export default function ComboAdresseSearch({
minimumInputLength={2}
transformResult={({ properties: { label } }) => [label, label, label]}
transformResults={(_, result) => (result as RawResult).features}
debounceDelay={300}
/>
</QueryClientProvider>
);

View file

@ -31,6 +31,7 @@ export type ComboSearchProps<Result> = {
describedby?: string;
className?: string;
placeholder?: string;
debounceDelay?: number;
};
type QueryKey = readonly [
@ -50,6 +51,7 @@ function ComboSearch<Result>({
transformResults = (_, results) => results as Result[],
id,
describedby,
debounceDelay = 0,
...props
}: ComboSearchProps<Result>) {
invariant(id || onChange, 'ComboSearch: `id` or `onChange` are required');
@ -59,7 +61,7 @@ function ComboSearch<Result>({
const [, setExternalId] = useHiddenField(group, 'external_id');
const initialValue = externalValue ? externalValue : controlledValue;
const [searchTerm, setSearchTerm] = useState('');
const [debouncedSearchTerm] = useDebounce(searchTerm, 300);
const [debouncedSearchTerm] = useDebounce(searchTerm, debounceDelay);
const [value, setValue] = useState(initialValue);
const resultsMap = useRef<
Record<string, { key: string; value: string; result: Result }>