import { useDebounce } from "use-any-hook";
function MyComponent() {
const [searchTerm, setSearchTerm] = useState("");
const debouncedSearchTerm = useDebounce(searchTerm, 1000);
const handleSearch = async () => {
const response = await fetch(
`https://dummyjson.com/products/search?q=${debouncedSearchTerm}`
);
};
useEffect(() => {
handleSearch();
}, [debouncedSearchTerm]);
return (
<input
type="text"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
);
}