Skip to content

Commit f6f6c00

Browse files
committed
chore: get rid of useDebounce
1 parent 820a560 commit f6f6c00

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

src/components/ui/combobox.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
PopoverContent,
1414
PopoverTrigger,
1515
} from "@/components/ui/popover";
16-
import { useDebounce } from "@/hooks/use-debounce";
1716
import { cn } from "@/lib/utils";
1817
import type React from "react";
1918
import { useEffect, useRef, useState } from "react";
@@ -43,25 +42,13 @@ export const LinearCombobox = ({
4342
const [searchValue, setSearchValue] = useState("");
4443
const onValueChangeRef = useRef(onValueChange);
4544
const isSearching = searchValue.length > 0;
46-
const { debouncedValue } = useDebounce(searchValue);
45+
4746
useEffect(() => {
4847
if (selectedOption && onValueChangeRef.current) {
4948
onValueChangeRef.current(selectedOption);
5049
}
5150
}, [selectedOption]);
5251

53-
useEffect(() => {
54-
if (Number.parseInt(debouncedValue) < options.length) {
55-
const possibleOption = options[Number.parseInt(debouncedValue)];
56-
if (possibleOption) {
57-
setSelectedOption(possibleOption);
58-
setOpenPopover(false);
59-
setSearchValue("");
60-
return;
61-
}
62-
}
63-
}, [debouncedValue, options]);
64-
6552
return (
6653
<Popover open={openPopover} onOpenChange={setOpenPopover} modal>
6754
<PopoverTrigger asChild>
@@ -98,7 +85,18 @@ export const LinearCombobox = ({
9885
<Command className="rounded-lg relative">
9986
<CommandInput
10087
value={searchValue}
101-
onValueChange={setSearchValue}
88+
onValueChange={(value) => {
89+
if (Number.parseInt(value) < options.length) {
90+
const possibleOption = options[Number.parseInt(value)];
91+
if (possibleOption) {
92+
setSelectedOption(possibleOption);
93+
setOpenPopover(false);
94+
setSearchValue("");
95+
return;
96+
}
97+
}
98+
setSearchValue(value);
99+
}}
102100
className="text-[0.8125rem] leading-normal"
103101
placeholder="Type Option no"
104102
/>

src/hooks/use-debounce.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)