examples/combobox-async.tsx
1"use client";23import * as React from "react";4import { Combobox } from "@/components/wensity/combobox";56const frameworkOptions = [7 { value: "nextjs", label: "Next.js" },8 { value: "remix", label: "Remix" },9 { value: "astro", label: "Astro" },10 { value: "sveltekit", label: "SvelteKit" },11];1213export function ComboboxAsync() {14 const [query, setQuery] = React.useState("");15 const [loading, setLoading] = React.useState(false);16 const [options, setOptions] = React.useState(frameworkOptions);1718 const handleSearchChange = React.useCallback(19 (nextQuery: string) => {20 setQuery(nextQuery);21 if (nextQuery !== query) setLoading(true);22 },23 [query],24 );2526 React.useEffect(() => {27 const timeout = window.setTimeout(() => {28 setOptions(29 frameworkOptions.filter((option) =>30 option.label.toLowerCase().includes(query.toLowerCase()),31 ),32 );33 setLoading(false);34 }, 400);35 return () => window.clearTimeout(timeout);36 }, [query]);3738 return (39 <Combobox40 label="Framework"41 placeholder="Search frameworks…"42 options={options}43 loading={loading}44 filter={false}45 onSearchChange={handleSearchChange}46 />47 );48}