diff --git a/examples/SearchBox.tsx b/examples/SearchBox.tsx new file mode 100644 index 0000000..428c5d8 --- /dev/null +++ b/examples/SearchBox.tsx @@ -0,0 +1,17 @@ +import { useState } from "react"; + +interface SearchBoxProps { + onSearch: (query: string) => void; + debounceMs?: number; +} + +export function SearchBox({ onSearch, debounceMs = 300 }: SearchBoxProps) { + const [value, setValue] = useState(""); + const handleChange = (next: string) => { + setValue(next); + setTimeout(() => { + onSearch(next); + }, debounceMs); + }; + return handleChange(e.target.value)} />; +}